幾個有趣的算法題目

本文首發 http://svtter.cn

最接近的數字

題目

一個K位的數N

$$ (K\leq2000,N\leq10^{20}) $$

找出一個比N大且最接近的數,這個數的每位之和與N相同,用代碼實現之。

例如:0050 所求書數字為0104;112 所求數為121;

算法分析 算法思想

直接暴力求這個數字是不可以的,數字的量級太大,有K位的數字,不可能直接用int,或者float來表示,使用數組來存儲。應該分析這個數字,step1,從右邊開始的最小位數開始,分解最后一位數字,分解出1來拿給前面的一位。9和0比較特殊,因此從左往右掃描的開始,遇到0就跳過,遇到第一個非0的數字,就把這個數字-1,然后移到最后面去,然后,step2,開始找第一個非9的數字,如果遇到9,就把9放到最后面去,遇到非9,就+1,結束運算。

一個般的例子:

1999000 -> 1990008-> 2000899

要注意一個問題,就是如果是 999000 這種情況,在數字的最開頭補1,結果是1000899

幾個刁蠻的數據:29399 -> 29489

偽代碼

array = get_array() # number to char array
array.reverse()
step1 = true
step2 = false
zero = 0, cnt = 0;
for i : 1 - lengthof(array)if step1:if array[i] is 0:zero ++else:array[i] = array[i] - 1if zero > 0:array[0] = array[i]array[i] = 0step1 = falsestep2 = trueelse if step2:if array[i] is 9:if zero == 0:array[cnt+1] = array[cnt]array[cnt] = 9cnt++if (i != cnt):array[i] = array[i-1]else:array[cnt + 1] = array[cnt]array[cnt] = 9cnt++array[i] = 0else:i = i+1step2 = falsebreakif not step2:array[lengthof(array)] = 1array.reverse()
disp(array)

分析時間復雜度O

因為reverse操作,2K,加上最后整理最小數到最前面,最壞情況接近K,3K,在循環中的操作看運氣,但是最糟糕的情況也只有5K,所以時間復雜度為

$$ O(3K) \approx O(K) $$

源代碼

#include <stdio.h>
#include <string.h>const int MAXN = 3000;
char array[MAXN];
int length_of_number;
void get_array()
{int i;char null;scanf("%d", &length_of_number);scanf("%c", &null);for (i = 0; i < length_of_number; i++){scanf("%c", &array[i]);}scanf("%c", &null);
}void reverse()
{int i ;char temp;for (i = 0; i < length_of_number/2; i++){// _swaptemp = array[i];array[i] = array[length_of_number - 1 - i];array[length_of_number-1-i] = temp;}
}void run()
{reverse();int step1 = 1,step2 = 0,i = 0,zero = 0,cnt = 0;for (i = 0; i < length_of_number; i++){if (step1){if (array[i] == '0'){zero++;}else{array[i] = array[i] - 1;if (zero > 0){array[cnt] = array[i];array[i] = '0';}step1 = 0, step2 = 1;}}else if (step2){if (array[i] == '9'){if (zero == 0){array[cnt + 1] = array[cnt];array[cnt] = '9';cnt++;if (i != cnt){array[i] = array[i-1];}}else{array[cnt + 1] = array[cnt];array[cnt] = '9';cnt++;array[i] = '0';}}else{array[i] ++;step2 = 0;break;}}}if (step2){array[length_of_number] = '1';length_of_number ++;}
}void output()
{int i;reverse();for(i = 0; i < length_of_number; i++){printf("%c", array[i]);}printf("\n");
}int main()
{memset(array, 0, sizeof(array));freopen("input", "r", stdin);get_array();run();output();return 0;
}

測試結果

使用python生成測試數據進行測試:

"""
最接近的數字
"""
import random
import osdef test():"""sample test"""num = random.randint(0, 10000000)sum_of_num = 0for i in str(num):sum_of_num += int(i)length = len(str(num))temp_num = num + 1while(True):sum_temp = 0for i in str(temp_num):sum_temp += int(i)if sum_temp == sum_of_num:breaktemp_num += 1with open('input', 'w') as f:f.write(str(length) + '\n')f.write(str(num))res = os.popen('./ex2').read()if temp_num == int(res):return [True]else:return [False, num, temp_num, int(res)]all = True
for i in range(1000):res = test()if res[0] is False:all = Falseprint(res)if all:print('Pass testing!')

存在錯誤的情況:

通過:

后期改善優化的地方

  1. reverse 是為了編程方便進行的處理,但是如果數字太大,速度肯定會受影響,這個時候就不要使用reverse了。

  2. 用鏈表來做可以簡化代碼,減少分析的,更加節省時間

  3. 處理移位的時候考慮幾個問題

尋找發帖水王

題目

如果“水王”沒有了,但有三個發帖很多的ID,發帖的數目都超過了帖子做數的1/4,又如何快速找出他們的ID。

算法分析 算法思想

從0-n掃描ID數組,記錄3個數字的個數,如果出現第四個數字,就把三個數字的個數減少1,如果有一個數字的個數減少到0,那么把新來的數字作為原本三個數字之一進行記錄。

如此一來,掃描完ID數組之后,剩下記錄的3個數字的個數便是需要求的三個數字。

偽代碼

array = get_array()
count = empty_set()
for i in array:if count.full:if i in count:count.i.num ++else:for j in count:count.j.num--elsecount.add(i)
disp(count)

分析時間復雜度O

數列的大小為N,記錄數字的數組大小為3,每次判斷記錄數組count是否存在0,以及找到已存在的數字++,都會花費3個單位時間,因此其時間復雜度為

$$ O(3n) \approx O(n) $$

源代碼

#include <stdio.h>
#include <string.h>#define MAXN 5000
int idarray[MAXN];int cur[3]; // 記錄當前元素
int pos[3]; // 記錄當前元素個數// 檢查是否在數組內,如果不在數組內,添加進入數組
void checkin(int no)
{int i;// 檢查是否有空位置for (i = 0; i < 3; i++){if (pos[i] == 0){cur[i] = no;pos[i] ++;return;}}// 尋找指定數字++for (i = 0; i < 3; i++){if (cur[i] == no){pos[i] ++;return;}}// 沒有找到重復數字,全部--for (i = 0; i < 3; i++)pos[i] --;
}// 輸出最后結果
void output()
{printf("%d %d %d\n", cur[0], cur[1], cur[2]);
}// 主程序
int numberOfArray;
void run()
{int i;for (i = 0; i < numberOfArray; i++){checkin(idarray[i]);}output();
}void input()
{int i;scanf("%d", &numberOfArray);for(i = 0; i < numberOfArray; i++){scanf("%d", &idarray[i]);}}int main()
{freopen("input", "r", stdin);int groupOfTest;scanf("%d", &groupOfTest);while(groupOfTest--){memset(cur, 0, sizeof(cur));memset(pos, 0, sizeof(pos));memset(idarray, 0, sizeof(idarray));input();puts("Test running...");run();}return 0;
}

測試結果

本測試數據采用Python自動生成。

"""
尋找發帖水王
"""import randomN = 4000
a, b = (int(N/4), int(N/3))
three_id = random.sample(range(1, 100), 3)
three_id_num = {}
sum_rand = 0
for i in three_id:temp = random.randint(a, b)sum_rand += tempthree_id_num[i] = three_id_num.get(i, 0) + tempid_array = [random.randint(1, 100) for i in range(N-sum_rand)]
for i in three_id:id_array = id_array + [i for j in range(three_id_num[i])]random.shuffle(id_array)print('Most three id:', three_id)
print('Three id num: ', three_id_num)
print('Sum of three_id num: ', sum_rand)
print('---------------')
# print(id_array)with open('input', 'w') as f:f.write('1\n')f.write(str(N) + '\n')for i in id_array:f.write(str(i) + ' ')

后期改善優化的地方

  1. 對于N比較小的情況可以在內存中進行查找,但是一旦涉及到更大的數據,這個方法可能就沒有那么簡單了,不能在內部建立數組,需要一部分一部分的從磁盤中讀數;

  2. 如果需要查找的id數量變多,那么需要的臨時保存的數列可能更大;

  3. 這個實現沒有使用STL中的map,如果使用map,還能進一步使得代碼見解易懂,map使用hash來做內部實現,可以使得面對數據量更大的數據的時候,加快查找數據的速度。

山西煤老板

題目

你是山西的一個煤老板,你在礦區開采了有3000噸煤需要運送到市場上去賣,從你的礦區到市場有1000公里,你手里有一列燒煤的火車,這個火車只能裝1000噸煤,且能耗比較大——每一公里需要耗一噸煤。請問,作為一個懂編程的煤老板,你會怎么運送才能運最多的煤到集市?

算法分析 算法思想

從動態規劃的角度求最優解:
假設起始運送貨物量為t,終點路程為s,火車容量為c,可以運抵終點的最多貨物量為函數 F(t, s)。
3種基本情況:
(1)t < s:貨物量不足以運送到此距離,所以F(t, s) = 0;
(2)s < t < c:火車一次就可以裝完貨物,所以F(t, s) = t - s;
(3)2s < c 使得火車一次無法運完,但可以采用往返的方式多次運輸,這種情況下最有的方式就是減少總共往返的次數,也就是直接運到終點而不在中間卸貨,所以

$$ F(t, s) = (t / c - 1) * (c - 2s) + (c - s) $$

可得遞歸式:

$$ F(t, s) = max\{ F( F(t, i), s - i)\} (1 <= i < s) $$

分析了一下這個方程是有問題的,比如F(1750, 250)會計算出1125;

所以正確的結果應該對t/c進行處理,也就是說,起點剩余的燃料不足運輸到終點,直接舍棄。第三階段的方程式應該是

$$ F(t, s) = (t // c - 1) * (c - 2s) + (c - s) + (t \% c - 2 s), if (t\%c > 2s) $$

偽代碼

begin:if t < s:f[t][s] = 0elif s < t < c:f[t][s] = t - selif 2*s < c:f[t][s] = int((t//c-1)*(c-2*s) + (c-s))if t % c > 2*s:f[t][s] += int(t % c-2*s)else:pre = -2for i in range(1, s):pre = int(max(F(F(t, i), s-i), pre))f[t][s] = pre
end
disp(f[3000][1000])

分析時間復雜度O

時間復雜度為

$$ O(3000*3000) $$

因為每個數字都要計算一遍。

源代碼

"""
山西煤老板
"""
c = 1000
f = [[-1 for k in range(4000)] for j in range(4000)]
for j in range(4000):for k in range(4000):if j < k:f[j][k] = 0
count = 1000
cnt = 0def F(t, s):"""dp"""global countglobal cglobal f# count -= 1# if count == 0:# count = int(input())t = int(t)s = int(s)if f[t][s] != -1:return f[t][s]if t < s:f[t][s] = 0elif s < t < c:f[t][s] = t - selif 2*s < c:f[t][s] = int((t//c-1)*(c-2*s) + (c-s))if t % c > 2*s:f[t][s] += int(t % c-2*s)else:pre = -2for i in range(1, s):pre = int(max(F(F(t, i), s-i), pre))f[t][s] = preprint(t, s, f[t][s])return f[t][s]print(F(3000, 500))

測試結果

后期改善優化的地方

  1. 去除了一下數據進行加速

  2. 保存f減少重復運算值

  3. 應該有更加簡單的方法,類似這種,但是不好解釋。

  4. $$ 3y=1000\\ 5x=1000\\ 解得x+y=200+333=533,因此使得最后一輛火車抵達時節省了533噸煤\\ $$

Facebook

題目

Given a list of words, L, that are all the same length, and a string, S, find the starting position of the substring of S that is concatenation of each word in L exactly once and without intervening characters. This substring will occur exactly once in S.

算法分析 算法思想

使用hashmap來保存word的hash值,來加快查找速度。(舊)

直接用hash函數求字符串的hash值,最后求得結果。

依據公式

$$ hash(w_1) + hash(w_2) = hash(w_2) + hash(w_1) $$

偽代碼

hash_word_list = list(map(hash, words))
hash_sum = reduce(lambda x, y: x + y, hash_word_list)for i in range(len(sentence)):wl = word_lenwlist = [sentence[i+j*wl:i+j*wl+wl] for j in range(words_len)]temp_sum = 0for k in wlist:temp_sum += hash(k)if temp_sum == hash_sum:print(i)break

分析時間復雜度O

就是字符串長度

$$ O(lengthOfS) $$

源代碼

#!/usr/bin/env python3
"""
facebook"""
from functools import reducewhile True:words = input()# words = "fooo barr wing ding wing"words = words.split(' ')word_len = len(words[0])words_len = len(words)hash_word_list = list(map(hash, words))hash_sum = reduce(lambda x, y: x + y, hash_word_list)sentence = input()# sentence = """lingmindraboofooowingdin\# gbarrwingfooomonkeypoundcakewingdingbarrwingfooowing"""# print(words, words_len, word_len, sentence)for i in range(len(sentence)):wl = word_lenwlist = [sentence[i+j*wl:i+j*wl+wl] for j in range(words_len)]# print(wlist)temp_sum = 0for k in wlist:temp_sum += hash(k)if temp_sum == hash_sum:print(i)break

測試結果

測試數據生成意義不是很大,

后期改善優化的地方

  1. hash盡管在速度上非常優秀,但是在準確度方面,如果出現hash沖突,那么值可能不準確。此時可以利用hashmap來解決這個問題,不過會多出重置hashmap的相關時間。

For n -m - problems

Problemset

Assume we have a sequence that contains N numbers of type long. And we know for sure that among this sequence each number does occur exactly n times except for the one number that occurs exactly m times (0 < m < n). How do we find that number with O(N) operations and O(1) additional memory?

Algorithm

^ is the add operation without carry.
默認one,two都是0, 即任何數字都不存在
數字a第一次來的時候, one標記a存在, two不變
數字a第二次來的時候, one標記a不存在, two標記a存在
數字a第三次來的時候, one不變, two標記a不存在

構造這樣一種運算,通過異或將數據保存在one和two里面。

Pseudocode

def solve2(array):one = 0, two = 0for i in range(array):one = (one ^ array[i]) & ~twotwo = (two ^ array[i]) & ~onereturn one, twoarray = input()
_, res = solve2(array)

### Source code

#!/usr/bin/env pythondef solve(array):one, two = 0, 0for i in array:one = (one ^ i) & ~twotwo = (two ^ i) & ~onereturn one, twoif __name__ == '__main__':array = input()array = array.split(' ')array = list(map(lambda x: int(x), array))# print(array)_, res = solve(array)print(res)

Test

#!/usr/bin/env python3
import randomdef test():"""測試"""array = []n, m = 3, 2numberofNum = random.randint(100, 1000)record = {}for _ in range(numberofNum):temp = random.randint(10, 10000)while temp in record:temp = random.randint(10, 10000)record[temp] = 1for _ in range(3):array.append(temp)temp = random.randint(10, 1000)while temp in record:temp = random.randint(10, 1000)array.append(temp)array.append(temp)from run import solve_, res = solve(array)if res != temp:print('ERROR')print(array, temp)input()else:print('Pass: res: ', res, 'temp:', temp)for i in range(50):test()

Use python generate data to test.

Discussion and improve

如果n不是3,那么需要構造更多的臨時變量。

很長的數組

題目

一個很長很長的short型數組A,將它分成m個長為L的子數組B1,B2,…,Bm,其中每個數組排序后都是遞增的等差數列,求最大的L值。

$$ 例如,A = \{-1, 3, 6, 1, 8, 10\} 可以分成B_1 = \{-1, 1, 3\}, B_2 = \{6, 8, 10\},\; L = 3 即為所求。 $$

算法分析

首先進行排序,然后開始分三步走。

  1. 統計元素個數 O(n)

  2. 排序 O(nlog(n))

    ?

第一步用來枚舉L和m的大小,由題目可知,L * m = 數組的長度。從m為1開始枚舉,保證得到的L為最大值。

第二步搜索為深搜,確定當前子數組的起點和初始步長,使用pos記錄當前數組選定的元素。

第三步枚舉,根據起點給定的初始步長,開始枚舉步長,如果枚舉的步長可以在數組中找到足夠的元素,即數字為L,那么記錄這種分法,開始枚舉下一個起點。如果枚舉的步長和起點無法滿足條件,回溯到上一個節點,把上一個節點記錄的步長+1再一次搜索。當枚舉的起點數達到m,即滿足要求輸出。

大白話來講,就是從頭開始分原始數組到m個數組中去,排序過后,在前面的每一個節點未被分配的元素,都是子數組起點。如果使用廣度優先搜索,即每次都給一個子數組分配一個滿足子數組步長要求的數,會導致在最后才發現分配的元素數不滿足要求,從而浪費大量時間。

其中,深度優先搜索還有幾個剪枝的技巧:

  1. 當前步長*(L-1)如果超過了數組的最大元素,可以不繼續搜索

  2. 如果在給定步長的情況下, 下一個數字的大小超過之前的數字+步長,那么可以不必繼續搜索。

    因為數組已經排好序。

  3. 還有其他的剪枝技巧,體現在代碼中了。

時間復雜度

n為數組長度,排序的時間為 O(nlogn),枚舉m時間為n,枚舉step時間為65536【short跨度】,枚舉全部元素時間為n,因此算法的時間上界為

$$ O(65536n^2) $$

實際情況下,由于剪枝等操作的存在,應優于這個時間。

偽代碼

leng = len(Array)
for m=1 to n:if n % m != 0:continueL = n // m# deep searchres, record = findArray(L, m)def findArray(L, m):group = 0pos = np.ones(leng)record = []record_start = []while group != m:step = 0start = getStart(pos)res, step = 尋找合適的步長(start, step, pos, record, L)if res:找到了計數while res is False:沒找到彈出棧,往回找if 彈出棧為空:不用找了找不到了return False, None

源代碼

#!/usr/bin/env python3
# coding: utf-8
"""
arrays
"""from __future__ import print_function
import numpy as nparray = [-1, 3, 6, 1, 8, 10]
# array = [1, 5, 9, 2, 6, 10]
# array = [1, 2, 4, 5, 8, 9, 13, 14]
# array = [1, 2, 4, 7, 11]
array = sorted(array)
print(array)
leng = len(array)
maxn = array[leng-1]
enable = 1
disable = 0def findJ(j, step, pos, record, L):"""尋找以J為開始,以步長step為開始的數列"""class StepError(Exception):passclass MaxException(Exception):passif pos[j] == disable:return Falsestart = array[j]pre = startrecord_temp = []# remember zerotry:for step in range(step, 40000):# 把第一個數字記錄record_temp.append(j)pos[j] = disablepre = startif start + step * (L - 1) > maxn:raise MaxExceptiontry:cnt = 1if cnt == L:record.append(record_temp)return True, stepfor k in range(j, leng):if pos[k] == disable:continueelif pos[k] == enable and array[k] == pre + step:record_temp.append(k)pre = array[k]cnt += 1pos[k] = disableelif pos[k] == enable and array[k] > pre + step:raise StepErrorif cnt == L:record.append(record_temp)return True, stepexcept StepError:# 重置標記for r in record_temp:pos[r] = enablerecord_temp = []except MaxException:# 沒有合適的stepreturn False, Nonedef findArray(L, m):"""尋找數組"""pos = np.ones(leng)record = []record_start = []group = 0while group != m:start = 0while pos[start] == disable:start += 1step = 0res, step = findJ(start, step, pos, record, L)if res:group += 1record_start.append((start, step))while res is False:try:start, step = record_start.pop()for r in record.pop():pos[r] = enablegroup -= 1res, step = findJ(start, step+1, pos, record, L)except IndexError:return False, Nonereturn True, recorddef divideArray():"""分離數組m 是分離的數組的個數L 是分離的數組的長度"""for m in range(1, leng+1):if leng % m != 0:continueL = leng // mres, record = findArray(L, m)def trans(x):return array[x]if res:print('lenth: ', L)for r in record:temp = map(trans, r)print(list(temp))returnprint('No result.')if __name__ == '__main__':divideArray()

測試

測試樣例生成結果未必準確,找了部分的測試樣例,可以通過修改代碼中array來提現。

討論

  1. 在記錄了起點和步長,應該可以利用這兩點推出當前使用了哪些元素,如果空間大小不夠使用,可以不適用record記錄,如果下一層不滿足條件回溯的時候,可以利用起點和步長回推已經使用的元素。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279785.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279785.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279785.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

獲取一篇新聞的全部信息

給定一篇新聞的鏈接newsUrl&#xff0c;獲取該新聞的全部信息 標題、作者、發布單位、審核、來源 發布時間:轉換成datetime類型 點擊&#xff1a; newsUrlnewsId(使用正則表達式re)clickUrl(str.format(newsId))requests.get(clickUrl)newClick(用字符串處理&#xff0c;或正則…

上twitter_如何在Twitter上更改您的顯示名稱

上twitterUnlike Facebook, Twitter has never insisted people user their real names. In fact, there’s a long tradition of people changing their names to a joke or pun because it’s Christmas or Halloween, or just for no reason at all. 與Facebook不同&#xf…

技術走向管理一些思考(1)-性格特質和自我管理

技術走向管理一些思考-文件夾 1&#xff0c;管理需具備的性格特質 贊賞他人&#xff1a;以一種不以自我為中心的合作的方式和他人相處&#xff0c;能平靜和客觀地接受不同的人。放下自己的性格、喜好&#xff0c;去贊賞不同類型的人。不是通過個人友誼或者熟悉程度。而是通過某…

網橋

配置實現網橋 網橋&#xff1a;即橋接 把一套機器上的若干個網絡接口 “連接” 起來&#xff0c;其結果是&#xff0c;其中一個網口收到的報文會被復制給其他網口并發送出去。以使得網口之間的報文能夠互相轉發。網橋就是這樣一個設備&#xff0c;它有若干個網口&#xff0c;并…

Newtonsoft.Json Deserialize Type 或者 同類型 變量 反序列化

Newtonsoft.Json 經常再用 這樣的需求 還是很少用 場景 方法一&#xff1a;根據 Type 反序列化 int demo 0; string jsongString JsonConvert.SerializeObject(demo); int jsonDemo JsonConvert.DeserializeObject(jsongString, demo.GetType()); 方法二 根據 同類型變量 序…

raspberry pi_在月光下將Raspberry Pi變成蒸汽機

raspberry piValve’s Steam Machines aim to bring your Steam game library right into your living room (but at a rather steep premium). Today we’ll show you how to bring your Steam library (plus all your other computer games) to your living room for a fract…

文檔測試【轉載】

原文來自&#xff1a;51Testing軟件測試網采編 作者&#xff1a; 仙靈測試(sinablog) 原文鏈接&#xff1a;http://www.51testing.com/html/61/n-237961.html 1、文檔的種類 ● 聯機幫助文檔或用戶手冊 這是人們最容易想到的文檔。用戶手冊是隨軟件發布而印制的小冊子…

NOI2019省選模擬賽 第三場

傳送門 明明沒參加過卻因為點進去結果狂掉\(rating\)…… \(A\) 集合 如果我們記 \[f_k\sum_{i1}^nT^i{n-i\choose k}\] 那么答案顯然就是\(f_{k-1}\) 然后就可以開始推倒了 \[ \begin{aligned} f_k &\sum_{i1}^nT^i{n-i\choose k}\\ &\sum_{i1}^nT^i{n-i-1\choose k}\…

MySql數據庫出現 1396錯誤

1、安裝MySql數據庫后。創建新的用戶。有可能會出現 1396這個錯誤&#xff0c; 2、解決的辦法如下&#xff1a;假裝有你需要創建的這個用戶、先刪了。再創建。 3、這樣就可以解決用戶創建不成功的問題了。 轉載于:https://www.cnblogs.com/chifa/p/9362882.html

如何使用wink框架_如何解決Wink Hub的Z-Wave連接問題

如何使用wink框架Overall, the Wink hub works extremely well…but sometimes the devices you have connected to it can act a little wonky. Here are some things you can do in order to fix any connection issues with all of those Z-Wave sensors and devices connec…

Tomcat服務器啟動錯誤之Offending class: javax/servlet/Servlet.class

引子 最近在基于Wex5項目開發中&#xff0c;遇到使用過程中與Tomcat功能有關的錯誤提示&#xff0c; 如題所示。最終的解決方法就是刪除掉項目上與tomcat沖突的jar包。 org.apache.catalina.loader.WebappClassLoader validateJarFile ??: validateJarFile(/Users/zxzpc/…

面向對象進階(二)----------類的內置方法

一、isinstance(obj,cls)和issubclass(sub,super) 1. isinstance(obj,cls): 檢查是否obj是否是類 cls 的對象 class Player:passp Player()print(isinstance(p, Player))>>> Ture 2. issubclass(sub, super): 檢查sub類是否是 super 類的派生類 class Player:passcla…

BZOJ.3265.志愿者招募加強版(費用流SPFA)

題目鏈接 見上題。 每類志愿者可能是若干段&#xff0c;不滿足那個...全幺模矩陣(全單位模矩陣)的條件&#xff0c;所以線性規劃可能存在非整數解。 于是就可以用費用流水過去順便拿個rank2 233. //20704kb 300ms #include <queue> #include <cstdio> #include &…

谷歌相冊_Google相冊中的新存檔功能是什么?

谷歌相冊If you’re a Google Photos user, you’ve may have seen a new feature called “Archive” show up in the app’s sidebar. if not, don’t stress—it’s just now rolling out and not everyone has it yet. Since it’s new, here’s a quick look at what it i…

CenterOS 7安裝Nginx

1.wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm下載對應當前系統版本的nginx包(package) 2.rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm建立nginx的yum倉庫 3.yum install nginx 下載并安裝nginx systemctl s…

Java的組合排列問題

從4個人中選2個人參加活動&#xff0c;一共有6種選法。 從n個人中選m個人參加活動&#xff0c;一共有多少種選法&#xff1f;C(m/n)C((m-1)/(n-1))C(m/(n-1))數學算法 public class Main {public static void main(String[] args) {System.out.println("請輸入總人數:&quo…

阿里云一鍵建站產品,阿里云自營建站-中小企業建站首選

阿里云推出的自營建站服務&#xff0c;這對于中小企業來說簡直是福利了&#xff0c;現在一般的公司都開始有了自己的官網&#xff0c;有可能就是因為你的官網設計的標準&#xff0c;大氣&#xff0c;客戶就會對你的信任度增加&#xff0c;從而促進一筆不小的訂單&#xff0c;這…

航拍拉近拉遠鏡頭_什么是遠攝鏡頭?

航拍拉近拉遠鏡頭Telephoto lenses can be incredibly useful, but how is it different from other lenses, and when should you use it? 遠攝鏡頭可能非常有用&#xff0c;但是它與其他鏡頭有什么不同&#xff1f;何時使用&#xff1f; 什么是遠攝鏡頭&#xff1f; (What I…

數據庫的簡單了解

數據庫一、什么是數據庫存儲數據的倉庫將數據有組織&#xff0c;按照特定的格式存儲在介質上叫做數據庫二、比較多個數據庫系統a) Oracle 最好的數據庫沒有之一b) SQL server 最好的數據庫(windows)c) MySQL 甲骨文(Oracle) sun 開源三、SQL語言a) SQL(結構化查詢語句) …

阿里云對象存儲OSS支持版本管理特性

2019獨角獸企業重金招聘Python工程師標準>>> 阿里云對象存儲OSS現已經全面支持“對象版本管理”特性。該功能適用于所有的存儲類型以及區域。當Bucket啟用該特性后&#xff0c;“對象版本管理”功能可以保護和恢復誤刪除、誤覆蓋的數據。 對象存儲OSS“版本管理”具…