国产性生交xxxxx免费-国产中文字幕-啊灬啊灬啊灬快灬高潮了,亚洲国产午夜精品理论片在线播放 ,亚洲欧洲日本无在线码,色爽交视频免费观看

鍋爐信息網(wǎng) > 鍋爐知識 > 鍋爐百科

CS 130B HW 2 Type up

發(fā)布時間:

Question 1:     Rmk:Question 2:Input:  dollars, bank  ,  , and fraction of amount kept for each bank  Output: maximum am

Question 1:

Rmk:

Question 2:

  • Input: dollars, bank , , and fraction of amount kept for each bank
  • Output: maximum amount of money that can be transferred.
  • The algorithm is then going to be a slight modification of Dijkstra's Algorithm, with the only difference being how the weight of each vertex is calculated.
  • In our algorithm, the weight of a vertex is calculated by .
  • Additionally, while the classical Dijkstra pops the vertex with the minimum weight from the priority queue, here we pop the vertex with the maximum weight (because it corresponds to our remaining balance).
  • return

b) The algorithm terminates because for each round, it adds a vertex to the list of vertices that has been visited. So the unvisited vertices will eventually run out and there's nothing to be added to the priority queue.

Correctness: It suffices to show our algorithm never makes a mistake (in the sense that always labels the vertex it visits--not the ones whose distance are upper bounded, but the ones that have been actually visited-- with the correct distance). The base case holds trivially. Then by induction, suppose it hasn't made a mistake on the i-th round, by the greedy nature of our algorithm, the (i+1)-th vertex it chooses to label must be correct . Since if it is not correct, then there must be some path to it that cost less the one which our algorithm has chosen, but the reason our algorithm didn't choose that path is because no unvisited vertex has cost smaller than that between our starting point and the (i+1)-th vertex (which is chosen by our algorithm at this round).

c) It should be clear that the complexity of our algorithm is the same as Dijkstra. .

Question 4:

a)Alg: ( )

  • Input: numbers , distance .
  • Output: number of pairs of people who live at most apart.
  • Store in an array and sort it.
  • Let be the counter of pairs of people that are at most distance apart
  • Let (as global variables)
  • Loop until :
    • Increase by one each time as long as and . Then decrease by one (because it is one beyond the distance range).
    • if : . (this is the situation when our window of size at most cannot include any person other than the person at its left endpoint).
    • else:
  • Output

b) Proof:

For each loop, we start with the person and keep increasing by one until . After decreasing by one from there, we know for sure that all people that are both 1)to the right of 2) is at most distance from , has been added to our output . The people who are 1)to the left of 2) at most distance from , has been previously counted, so there's no need to count them.

In a slightly concise way, we could express the above paragraph in one sentence:

where means the th person instead of the distance.

Since the loops terminates only when , we have cover the entire range , so we have included every pair possible and have not over-counted. Therefore, the algorithm is correct.

c)

Sorting the array:

Going through loop:

Total:

精選推薦

  • 711關東煮供應商
    711關東煮供應商

    今天給大家介紹三位,奶粉,全家、羅森這些便利店里關東煮的供應商。店里賣三四塊錢一串的關東煮,在網(wǎng)上買不到,一塊錢就搞定。首先關東

  • 健康日歷|高壓鍋容易爆炸的4個原因
    健康日歷|高壓鍋容易爆炸的4個原因

    來源:醫(yī)藥養(yǎng)生保健報設計:李雅琴醫(yī)學審核:姜峰出品人:胡麗麗

  • 高爐
    高爐

    今天這活卻是個白事,等到了時辰,那家人便準備火化,本來準備送普爐,我卻心中一動,便對那家人說道:“這老人走也不要省,還是送高爐吧。”

  • 高壓鍋和電壓力鍋的區(qū)別,推薦幾款點壓力鍋
    高壓鍋和電壓力鍋的區(qū)別,推薦幾款點壓

    記得之前有一次去朋友家玩,他正在用高壓鍋煮小米粥,是的,高壓鍋壓小米粥,大概煮了半小時,高壓鍋突然爆炸了,現(xiàn)場慘不忍睹啊,幸好廚房里沒

0