日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

2019 GDUT Rating Contest I : Problem H. Mixing Milk

發(fā)布時間:2023/11/27 生活经验 62 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019 GDUT Rating Contest I : Problem H. Mixing Milk 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題面:

H. Mixing Milk

Input ?le: standard input Output ?le: standard output Time limit: 1 second Memory limit: 256 megabytes Farming is competitive business – particularly milk production. Farmer John ?gures that if he doesn’t innovate in his milk production methods, his dairy business could get creamed! Fortunately, Farmer John has a good idea. His three prize dairy cows Bessie, Elsie, and Mildred each produce milk with a slightly di?erent taste, and he plans to mix these together to get the perfect blend of ?avors.

To mix the three di?erent milks, he takes three buckets containing milk from the three cows. The buckets may have di?erent sizes, and may not be completely full. He then pours bucket 1 into bucket 2, then bucket 2 into bucket 3, then bucket 3 into bucket 1, then bucket 1 into bucket 2, and so on in a cyclic fashion, for a total of 100 pour operations (so the 100th pour would be from bucket 1 into bucket 2). When Farmer John pours from bucket a into bucket b, he pours as much milk as possible until either bucket a becomes empty or bucket b becomes full.

Please tell Farmer John how much milk will be in each bucket after he ?nishes all 100 pours. Input The ?rst line of the input ?le contains two space-separated integers: the capacity c1 of the ?rst bucket, and the amount of milk m1 in the ?rst bucket. Both c1 and m1 are positive and at most 1 billion, with c1 ≤ m1. The second and third lines are similar, containing capacities and milk amounts for the second and third buckets. Output Please print three lines of output,giving the ?nal amount of milk in each bucket, after 100 pouroperations. Example Input 10 3 11 4 12 5 Output 0 10 2 Note In this example, the milk in each bucket is as follows during the sequence of pours: Initial State: 3 4 5
  1. Pour 1->2: 0 7 5
  2. Pour 2->3: 0 0 12
  3. Pour 3->1: 10 0 2
  4. Pour 1->2: 0 10 2
  5. Pour 2->3: 0 0 12
(The last three states then repeat in a cycle ...)

題目描述:

有三個桶,每個桶都有不同量的牛奶。第一次:把第1個桶的牛奶倒進第2個桶,直到第2個桶倒?jié)M或者第1個桶的牛奶倒完。第二次:把第2個桶的牛奶倒進第3個桶,直到第3個桶倒?jié)M或者第2個桶的牛奶倒完。第三次:把第3個桶的牛奶倒進第1個桶,直到第1個桶倒?jié)M或者第3個桶的牛奶倒完。第四次:重復(fù)第一次的操作。第五次:重復(fù)第二次的操作......,進行了100次倒牛奶的操作,問:現(xiàn)在三個桶里面有多少牛奶?

題目分析:

這道題直接模擬:我們分析一下”倒“牛奶的操作: 把左邊桶的牛奶倒進右邊的桶,有兩種情況: 1.左邊的牛奶全部倒進右邊: 2.左邊的牛奶還有剩余: ? 對于第一種情況,先把左邊牛奶的量加到右邊,然后才把左邊的牛奶的量清空(直接設(shè)為0)。這里容易錯的地方就是有的人會把這兩個的先后順序搞反,導(dǎo)致自己看起來好像明明邏輯對了,但結(jié)果就是不對。原因:如果先把左邊牛奶的量清空,我們就不知道要從左邊倒多少牛奶到右邊,錯誤代碼導(dǎo)致的示意圖: 對于第二種情況,先把左邊剩下多少牛奶計算出來,然后把右邊的牛奶加滿(直接設(shè)為容量)。這里容易錯的地方道理和剛剛差不多: ? 最后,我們把這個過程弄一個函數(shù),然后按照題目意思直接調(diào)用這個倒牛奶的函數(shù)就行了。(雖然是道水題,但也不能忽視一些小錯誤o(≧口≦)o,寫題解時發(fā)現(xiàn)自己當時的ac代碼(無函數(shù)版)真丑┭┮﹏┭┮) AC代碼:
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 using namespace std;
 5 int capa[5], leave[5];
 6 
 7 void pour(int a, int b){
 8     if(leave[a]+leave[b] <= capa[b]){  //第一種情況
 9         leave[b] += leave[a];
10         leave[a] = 0;
11     }
12     else{   //第二種情況
13         leave[a] -= capa[b]-leave[b];
14         leave[b] = capa[b];
15     }
16 }
17 
18 int main(){
19     for(int i = 1; i <= 3; i++){
20         cin >> capa[i] >> leave[i];
21     }
22 
23     for(int i = 0; i < 33; i++){
24         pour(1, 2);   //桶1倒進桶2
25         pour(2, 3);   //桶2倒進桶3
26         pour(3, 1);   //桶3倒進桶1
27     }
28 
29     pour(1, 2);   //最后別忘這個
30 
31     for(int i = 1; i <= 3; i++){
32         cout << leave[i] << endl;
33     }
34     return 0;
35 }

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/happy-MEdge/p/10530730.html

總結(jié)

以上是生活随笔為你收集整理的2019 GDUT Rating Contest I : Problem H. Mixing Milk的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。