[usaco]1.4 Mother’s Milk
2012-07-10 09:24
309 查看
分析后 和之前的类似,每一步有六种状态转移的方式 : c->a ;c->b; a->c;b->c,a->b ;b->a
那每个状态是 a,b,c 的牛奶数量,因为是是从1 -20 ,那么等于是有20^3种状态、
和之前的clock 很像,标记状态hash 判重,遍历所有的情况就可以。
原始博客地址:http://www.fuxiang90.com/2012/06/usaco1-4-mothers-milk/
那每个状态是 a,b,c 的牛奶数量,因为是是从1 -20 ,那么等于是有20^3种状态、
和之前的clock 很像,标记状态hash 判重,遍历所有的情况就可以。
/* ID:fuxiang2 PROG: ariprog LANG: C++ */ #include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <algorithm> #include <set> #include <cmath> #define REP(i, n) for (int i=0;i<int(n);++i) #define FOR(i, a, b) for (int i=int(a);i<int(b);++i) #define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i) #define REP_1(i, n) for (int i=1;i<=int(n);++i) #define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i) #define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i) using namespace std; ofstream fout ("ariprog.out"); ifstream fin ("ariprog.in"); int n,m; //set<int> si; int hash[62510 * 2]; class node { public: int a; int b; node(int _a, int _b){ a = _a; b = _b; } bool operator < (const node & m )const { if(m.b == b) return a < m.a; return b < m.b; } }; vector<node> vn; //应该是这里比较费时间 void work(int a,int b) { int ans = a; if(hash[ans] == 0) return ; FOR(i,0,n-1){ ans += b; if(hash[ans] == 0) return ; } node t(a,b); vn.push_back(t); } int main() { fin >> n >> m; FOR_1(i,0,m) FOR_1(j,0,m){ int ii = i*i; int jj = j*j; hash[ii + jj] = 1; } int end = m*m ; FOR_1(i,0,end) FOR_1(j,1,end){ if( (i + (n-1)*j) <= 2*end) work(i,j); else break; } sort(vn.begin(),vn.end()); if(vn.empty()) fout << "NONE"<<endl; else for(vector<node>::iterator iter = vn.begin() ; iter != vn.end() ; iter ++ ){ fout << iter->a << " "<< iter ->b<<endl; } return 0; }
原始博客地址:http://www.fuxiang90.com/2012/06/usaco1-4-mothers-milk/
相关文章推荐
- USACO Section 1.4 Mother's Milk
- USACO 1.4-Mother's Milk
- USACO Section 1.4 Mother's Milk 搜索
- USACO 1.4 Mother's Milk (枚举 + DFS)
- [USACO-Training 1.4]Mother's Milk
- USACO Section 1.4 - Mother's Milk(DFS + 记忆化)
- USACO1.4 母亲的牛奶 Mother's Milk
- USACO-Section1.4 Mother's Milk [搜索]
- USACO 1.4 Mother's Milk (milk3)
- USACO 1.4 Mother's Milk
- USACO 1.4 - Mother's Milk(DFS)
- USACO 1.4 Mother's Milk___dfs
- 【模拟递规】Mother's Milk 母亲的牛奶 (Usaco_Training 1.4)
- USACO-Section1.4 Mother's Milk
- USACO-Section 1.4 Mother's Milk(BFS)
- 【搜索】洛谷 P1215 [USACO1.4]母亲的牛奶 Mother's Milk
- USACO-Section1.4 Mother's Milk
- USACO 1.4 Mother's Milk
- USACO Section 1.4 Mother's Milk - 输出错了好几次..
- Mother's Milk_usaco1.4_bfs