USACO 1.4 Mother's Milk (milk3)
来源:互联网 发布:java中long的长度 编辑:程序博客网 时间:2024/05/16 05:55
/*ID: haolink1PROG: milk3LANG: C++*///#include <iostream>#include <fstream>using namespace std;//Use global varible to reduce the function DFS's agumentsconst short max_value = 20;bool bucket_state[max_value+1][max_value+1];short a_capacity = 0;short b_capacity = 0;short c_capacity = 0;bool c_remain[max_value+1] = {false}; short Max(short first,short second){ if(first >= second) return first; else return second;}short Min(short first,short second){ if(first <= second) return first; else return second;}void DFS(short a,short b,short c){ if(bucket_state[a][b] == true) return; bucket_state[a][b] = true; if(a == 0) c_remain[c] = true; //There are total 6 cases to pour bucket.Once pouring begin,it won't end unless //either the soucr bucket is empty or the target bucket is full. //a->b if(a > 0 && b < b_capacity) DFS(Max(0,a+b-b_capacity),Min(b_capacity,a+b),c); //a->c if(a > 0 && c < c_capacity) DFS(Max(0,a+c-c_capacity),b,Min(c_capacity,a+c)); //b->a if(b > 0 && a < a_capacity) DFS(Min(a_capacity,a+b),Max(0,a+b-a_capacity),c); //b->c if(b > 0 && c < c_capacity) DFS(a,Max(0,b+c-c_capacity),Min(c_capacity,b+c)); //c->a if(c > 0 && a < a_capacity) DFS(Min(a_capacity,a+c),b,Max(0,a+c-a_capacity)); //c->b if(c > 0 && b < b_capacity) DFS(a,Min(b_capacity,b+c),Max(0,b+c-b_capacity));}int main(){ ifstream fin("milk3.in"); fin >> a_capacity; fin >> b_capacity; fin >> c_capacity; for(short i = 0; i < max_value; i++){ for(short j = 0; j < max_value; j++){ bucket_state[i][j] = false; } } DFS(0,0,c_capacity); ofstream fout("milk3.out"); for(short i = 0; i < c_capacity; i++){ if(c_remain[i] == true) fout << i <<" "; } // c_capacity is always qualified; fout<<c_capacity<<endl;}
0 0
- USACO 1.4 Mother's Milk (milk3)
- [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
- Mother's Milk(usaco)
- usaco Mother's Milk
- USACO:Mother's Milk
- USACO-Mother's Milk
- USACO Mother's Milk
- USACO Mother's Milk
- USACO Mother's Milk
- USACO: Mother's Milk
- USACO Mother's Milk
- usaco Mother's Milk
- USACO1.4.2 Mother's Milk (milk3)
- USACO 1.4 Arithmetic Progressions (ariprog)
- JS控制弹窗增加确定和取消
- C语言的服务器开发基础知识
- 积分触发器 mysql 触发器的使用
- 画用例图
- USACO 1.4 Mother's Milk (milk3)
- 如何查看道琼斯指数
- 离线搭建android环境
- SAS决策树:信贷风险建模试验
- c# 统计物理内存百分比
- USACO 1.5 Number Triangles (numtri)
- Android基于Google云端的Voice Search
- 特征变换以及维度下降——Linear Discriminant Analysis(二)
- 二分法