# 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;
 } 

你可能感兴趣的:(题解)