USACO Section 1.4 Mother's Milk
来源:互联网 发布:极光衬肩 数据库 编辑:程序博客网 时间:2024/05/17 00:59
题目描述
农民约翰有三个挤奶桶的容量A,B和C升。 数字A,B和C中的每一个为1至20的整数,包括1和20。 最初,桶A和瓶B都是空的,而桶C已经满了牛奶。 有时,FJ将牛奶从一个桶倒入另一个桶中,直到第二个桶装满,或者第一个桶是空的。 一旦开始,必须完成倾倒,当然。 节俭,不会抛出牛奶。编写一个程序来帮助FJ确定在桶C中可以离开的牛奶量,当他从上面的三个桶开始时,在桶中倒入牛奶一段时间,然后注意到A桶是空的。
程序名称:milk3
输入格式
具有三个整数A,B和C的单行。
输入 (file milk3.in)
8 9 10
输出格式
一行,当桶A为空时,可以在桶C中的所有可能的牛奶量排序列表。
输出(file milk3.out)
1 2 8 9 10输入 (file milk3.in)
2 5 10输出(file milk3.out)
5 6 7 8 9 10解题思路
本题主要的解题思路在于,在每次到的过程中出现第一个是0的第三个瓶内的牛奶数记录下来。
解题代码
/*ID: 15189822PROG: milk3LANG: C++*/#include<iostream>#include<cstring>#include<fstream>using namespace std;ifstream fin("milk3.in");ofstream fout("milk3.out");const int N = 20;int a,b,c;int f[N+1];int jg[N+1];int d[N+1][N+1];void dfs(int x,int y,int z){ int t; d[x][y]=1; if (x==0){ f[z]=1; } if (x>0&&y!=b){ t=min(x,b-y); if (!d[x-t][y+t]) dfs(x-t,y+t,z); } if (x>0&&z!=c){ t=min(x,c-z); if (!d[x-t][y]) dfs(x-t,y,z+t); } if (y>0&&x!=a){ t=min(a-x,y); if (!d[x+t][y-t]) dfs(x+t,y-t,z); } if (y>0&&z!=c){ t=min(c-z,y); if (!d[x][y-t]) dfs(x,y-t,z+t); } if (z>0&&x!=a){ t=min(a-x,z); if (!d[x+t][y]) dfs(x+t,y,z-t); } if (z>0&&y!=b){ t=min(b-y,z); if (!d[x][y+t]) dfs(x,y+t,z-t); }}int main(){ memset (f,0,sizeof(f)); memset (d,0,sizeof(d)); fin>>a>>b>>c; dfs(0,0,c); int i,j,s1=0,s2=0; for (i=0;i<=N;i++){ if (f[i]){ jg[s1]=i; s1++;} } for (i=0;i<s1-1;i++){ fout<<jg[i]<<" "; } fout<<jg[s1-1]<<endl; return 0;}
阅读全文
0 0
- USACO Section 1.4 Mother's Milk 搜索
- USACO section 1.4.4 Mother's Milk
- USACO Section 1.4 Mother's Milk
- USACO Section 1.4 Mother's Milk
- USACO Section 1.4 Mother's Milk
- USACO Section 1.4 Mother's Milk - 输出错了好几次..
- USACO Section 1.4 - Mother's Milk(DFS + 记忆化)
- USACO-Section 1.4 Mother's Milk(BFS)
- Section 1.4 Mother's Milk
- [usaco]1.4 Mother’s Milk
- USACO 1.4 Mother's Milk
- USACO 1.4 Mother's Milk
- USACO 1.4-Mother's Milk
- USACO 1.4 Mother's Milk
- USACO 1.4 Mother's Milk
- USACO-Section 1.4 Mother Milk[模拟][搜索]
- Mother's Milk(usaco)
- usaco Mother's Milk
- 程序员职业生涯全攻略,附神级跳槽攻略图
- echo
- Web总结----Http协议
- 我如何选择了流行的PHP
- 安卓开发批量修改指定字符串,去除粘贴复制代码中的多余红线
- USACO Section 1.4 Mother's Milk
- AngularJs学习之路(六)
- C# 接口是否可以包含字段
- Oracle 函数function之返回结果集
- [POJ](2485)Highways ---最小生成树(图)
- HTML 你最该知道的几个知识点
- 记一次晋升答辩
- 最小代价生成树
- 阳历以及阳历的闰年