2019 GDUT Rating Contest I : Problem H. Mixing Milk
题面:
H. Mixing Milk
To mix the three different milks, he takes three buckets containing milk from the three cows. The buckets may have different 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.
- Pour 1->2: 0 7 5
- Pour 2->3: 0 0 12
- Pour 3->1: 10 0 2
- Pour 1->2: 0 10 2
- Pour 2->3: 0 0 12
题目描述:
题目分析:


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 }
2019 GDUT Rating Contest I : Problem H. Mixing Milk的更多相关文章
- 2019 GDUT Rating Contest II : Problem F. Teleportation
题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...
- 2019 GDUT Rating Contest III : Problem D. Lemonade Line
题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...
- 2019 GDUT Rating Contest I : Problem A. The Bucket List
题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem G. Back and Forth
题面: G. Back and Forth Input file: standard input Output file: standard output Time limit: 1 second Mem ...
- 2019 GDUT Rating Contest III : Problem E. Family Tree
题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe
题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2019 GDUT Rating Contest III : Problem A. Out of Sorts
题面: 传送门 A. Out of Sorts Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest II : Problem C. Rest Stops
题面: C. Rest Stops Input file: standard input Output file: standard output Time limit: 1 second Memory ...
随机推荐
- Clipboard API
Clipboard API click copy click copy demo clickGetNewsLink(data_ref = `newsLink`) { let that = this; ...
- docker-compose All In One
docker-compose All In One docker-compose 多容器应用 $ docker-compose -h Define and run multi-container ap ...
- React render algorithm & Fiber vs Stack
React render algorithm & Fiber vs Stack React 渲染算法 & Fiber vs Stack https://stackoverflow.co ...
- how to read the 10th line of a text using shell script
how to read the 10th line of a text using shell script shell script / bash script question https://l ...
- nasm astrrchr函数 x86
xxx.asm %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain export ast ...
- HDFS 01 - HDFS是什么?它的适用场景有哪些?它的架构是什么?
目录 1.HDFS 是什么 1.1 简单介绍 1.2 发展历史 2.HDFS 应用场景 2.1 适合的应用场景 2.2 不适合的应用场景 3.HDFS 的架构 4.NameNode 和 DataNod ...
- NGK生态之星空计划启动在即,稀有VAST高兑换比带来高价值!
NGK生态之星空计划启动在即,为了感谢NGK布道者的支持,NGK官方将全力辅助算力市场,开展全新的星空计划,并发行星空币SPC,空投给算力持有者进行额外奖励. 至此,SPC已经顺利完成2轮空投,也初步 ...
- 「NGK每日快讯」12.22日NGK第49期官方快讯!
- BGV币与YFI币、YFII币存在着怎样的相关性?
大多数的玩家并没有长期的打算,而是更倾向于关注短期利好的币种.比如最近在圈内赚足眼球的YFI,之所以能够成为明星角色,并非它的技术和平台,而是因为它在短期就创造了86倍的暴涨.YFI币的暴涨在某种程度 ...
- 精密进近OCH的计算
一.计算步骤 以I类精密进近为例,运行标准的制定大致分为以下几个步骤: 1)确定精密航段的超高障碍物. 2)计算当量高 3)计算高度损失 4)当量高与高度损失相加得到超障高OCH 5)对复飞段障碍物进 ...