2019 GDUT Rating Contest #I H. Mixing Milk 【# 2019 GDUT Rating Contest #I H. Mixing Milk】题目见 :
http://codeforces.com/group/NVaJtLaLjS/contest/238166/problem/H
题目大意: 又是奶!!!
有3个桶,给出容量和里面的奶量,从一号开始,把一个桶里的奶倒到下一个桶里,原桶要倒完或者下个桶要倒满。这样100次,问你最终结果状态。
思路: 还是直接dfs搜索模拟即可。??快累死了
一次优化: 可以先自己刷几个循环,找到规律:(额,不过我好像没找哎)
实现:
#include
#include
#include
using namespace std;
int main()
{
int i,j,now,next;
int v[3],f[3];
for (i=1;
i<=3;
i++)
{
scanf("%d %d",&v[i-1],&f[i-1]);
}
now=0;
for (i=1;
i<=100;
i++)
{
next=(now+1)%3;
f[next]+=f[now];
f[now]=0;
if (f[next]>v[next])
{f[now]=f[next]-v[next];
f[next]=v[next];
}
now=next;
}
printf("%d\n%d\n%d\n",f[0],f[1],f[2]);
return 0;
}
推荐阅读
- 题解|【HNOI2017】大佬-dalao
- 2019 GDUT Rating Contest #II 这是群题解,七篇!!!
- # 2019 GDUT Rating Contest #I A. The Bucket List
- # 2019 GDUT Rating Contest #I G. Back and Forth
- 2019 GDUT Winter Personal Training Contest III (Div. 2) A题 QAQ 题解
- 2019 GDUT Winter Personal Training Contest I (Div. 2) A. Protect Sheep
- 题解|题解 | K-ary Heap-2019牛客暑期多校训练营第六场F题
- ACM|[dsu] codeforces 375D. Tree and Queries
- 题解|[BZOJ3817] Sum