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
题目描述:
题目分析:
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314152123931-1266140049.png)
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314152937467-1750086841.png)
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314153005216-1523810572.png)
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314153115566-1729879567.png)
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314153155334-1897928482.png)
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314153814815-2058720165.png)
![](https://img2018.cnblogs.com/blog/1591738/201903/1591738-20190314154218621-1554159759.png)
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 ...
随机推荐
- 力扣119.杨辉三角II-C语言实现
题目 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 3 输出: [1,3,3,1] 来源:力扣(LeetCod ...
- leetcode5 最长回文字符串 动态规划 Manacher法
dp 注意没有声明S不空,处理一下 o(n^2) class Solution { public: string longestPalindrome(string s) { if (s.empty() ...
- 牛客多校第五场B generator1(十进制矩阵快速幂)题解
题意: 已知 \(X_i = a * X_{i - 1} + b * X_{i - 2}\),现给定\(X_0,X_1,a,b\),询问\(X^n \mod p\),其中\(n <= 10^{1 ...
- HDU4565-数学推导求递推公式+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 我们带着这个根号是没法计算的 我们仔细观察一下,(a+sqrt(b))^n用二项式定理展开,我 ...
- vue 如何重绘父组件,当子组件的宽度变化时候
vue 如何重绘父组件,当子组件的宽度变化时候 vue & dynamic el-popover position demo https://codepen.io/xgqfrms/pen/wv ...
- 「NGK每日快讯」2021.2.1日NGK公链第90期官方快讯!
- 源码分析:CyclicBarrier 之循环栅栏
简介 CyclicBarrier 是一个同步辅助工具,允许一组线程全部等待彼此达到共同屏障点,且等待的线程被释放后还可以重新使用,所以叫做Cyclic(循环的). 应用场景 比如出去旅行时,导游需要等 ...
- 配置伪分布模式下的hadoop以及采用fuse-dfs来访问HDFS
实验目标 配置环境的主要目的是得到HDFS的客户端fuse-dfs的IO性能.本来的服务器上没有任何环境,因此安装均是从无到有的.系统是Ubuntu server 14.04 amd64.整个过程参考 ...
- Linux进程管理工具Supervisor的安装配置
目录 Linux进程管理工具Supervisor的安装配置 简介 安装Python包管理工具 安装Supervisor 配置 配置文件参数说明 配置进程管理 启动supervisor 控制进程 交互终 ...
- Django之csrf中间件及auth模块使用
目录 一.基于配置文件的编程思想 1. importlib 模块 2. 配置文件 二.跨站请求伪造(csrf) 1.csrf简介以及由来 2.Django中的csrf中间件如何使用 2.1 普通for ...