Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求测试数据阿阿阿阿阿阿阿#include <iostream> #include <queue> #include <stack> using namespace std; int visited[100][100] = {0}; class ab { public: int A; int B; int sign; ab *p; }; void solution(int A,int B,int C) { queue<ab> q; stack<ab> out; ab tmpg[10000]; int g = 0; ab tmp,tmpp; int time = 0; tmp.A = 0; tmp.B = 0; tmp.sign = 0; tmp.p = NULL; q.push(tmp); visited[tmp.A][tmp.B] = 1; while(q.empty()!=1) { tmp = q.front(); if(tmp.A == C || tmp.B == C) { for(;tmp.sign != 0;) { out.push(tmp); time++; tmp = *(tmp.p); } cout<<time<<endl; for(int i = 0;i < time;i++) { tmp = out.top(); out.pop(); if(tmp.sign == 1) { cout<<"FILL(1)"<<endl; continue; } if(tmp.sign == 2) { cout<<"FILL(2)"<<endl; continue; } if(tmp.sign == 3) { cout<<"DROP(1)"<<endl; continue; } if(tmp.sign == 4) { cout<<"DROP(2)"<<endl; continue; } if(tmp.sign == 5) { cout<<"POUR(1,2)"<<endl; continue; } if(tmp.sign == 6) { cout<<"POUR(2,1)"<<endl; continue; } } return; } else { q.pop(); tmpp.A = A; tmpp.B = tmp.B; if(visited[tmpp.A][tmpp.B] == 0) { tmpp.sign = 1; tmpg[g] = tmp; tmpp.p = &tmpg[g]; g++; q.push(tmpp); visited[tmpp.A][tmpp.B] = 1; } tmpp.A = tmp.A; tmpp.B = B; if(visited[tmpp.A][tmpp.B] == 0) { tmpp.sign = 2; tmpg[g] = tmp; tmpp.p = &tmpg[g]; g++; q.push(tmpp); visited[tmpp.A][tmpp.B] = 1; } tmpp.A = 0; tmpp.B = tmp.B; if(visited[tmpp.A][tmpp.B] == 0) { tmpp.sign = 3; tmpg[g] = tmp; tmpp.p = &tmpg[g]; g++; q.push(tmpp); visited[tmpp.A][tmpp.B] = 1; } tmpp.A = tmp.A; tmpp.B = 0; if(visited[tmpp.A][tmpp.B] == 0) { tmpp.sign = 4; tmpg[g] = tmp; tmpp.p = &tmpg[g]; g++; q.push(tmpp); visited[tmpp.A][tmpp.B] = 1; } tmpp.A = tmp.A; tmpp.B = tmp.B; tmpp.B = tmp.B + tmp.A; if(tmpp.B > B) { tmpp.B = B; tmpp.A = tmp.A - (B - tmp.B); } else { tmpp.A = tmpp.A - (tmpp.B - tmp.B); } if(visited[tmpp.A][tmpp.B] == 0) { tmpp.sign = 5; tmpg[g] = tmp; tmpp.p = &tmpg[g]; g++; q.push(tmpp); } tmpp.A = tmp.A; tmpp.B = tmp.B; tmpp.A = tmp.A + tmp.B; if(tmpp.A > A) { tmpp.A = A; tmpp.B = tmp.B - (A - tmp.A); } else { tmpp.B = tmpp.B - (tmpp.A - tmp.A); } if(visited[tmpp.A][tmpp.B] == 0) { tmpp.sign = 6; tmpg[g] = tmp; tmpp.p = &tmpg[g]; g++; q.push(tmpp); } } } cout<<"impossible"<<endl; return; } int main(void) { int A,B,C; cin>>A>>B>>C; solution(A,B,C); return 0; } 不知道哪错。。。。提交NN次了阿 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator