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 |
写的好烦 但是1A#include <iostream> #include <cstdio> #include <cstring> #include <queue> #define maxn 10000 #define maxm 110 using namespace std; struct node { int a,b; int next,opra; }; int a,b,c; int ans; node que[maxn]; bool vis[maxm][maxm]; int front,tail; void init() { ans=0; front=0,tail=0; memset(vis,false,sizeof(vis)); } void full(node temp,int i) { if(i==1)temp.a=a,temp.next=front,temp.opra=1; else temp.b=b,temp.next=front,temp.opra=2; if(!vis[temp.a][temp.b])que[tail++]=temp,vis[temp.a][temp.b]=true; } void drop(node temp,int i) { if(i==1)temp.a=0,temp.next=front,temp.opra=3; else temp.b=0,temp.next=front,temp.opra=4; if(!vis[temp.a][temp.b])que[tail++]=temp,vis[temp.a][temp.b]=true; } void pour(node temp,int from,int to) { if(from==1) { if(temp.a>=b-temp.b) { temp.a=temp.a-b+temp.b,temp.b=b; temp.next=front,temp.opra=5; } else { temp.b+=temp.a,temp.a=0; temp.next=front,temp.opra=5; } } else { if(temp.b>=a-temp.a) { temp.b=temp.b-a+temp.a,temp.a=a; temp.next=front,temp.opra=6; } else { temp.a+=temp.b,temp.b=0; temp.next=front,temp.opra=6; } } if(!vis[temp.a][temp.b])que[tail++]=temp,vis[temp.a][temp.b]=true; } void print(int i) { ans++; if(i<=0) { printf("%d\n",ans-1); return; } print(que[i].next); int temp=que[i].opra; if(temp==1)printf("FILL(1)\n"); else if(temp==2)printf("FILL(2)\n"); else if(temp==3)printf("DROP(1)\n"); else if(temp==4)printf("DROP(2)\n"); else if(temp==5)printf("POUR(1,2)\n"); else printf("POUR(2,1)\n"); } void slove() { init(); node state; bool flag=false; state.a=0,state.b=0,state.next=0;state.opra=0; que[tail++]=state; vis[state.a][state.b]=true; while(tail!=front) { node temp=que[front]; if(temp.a==c||temp.b==c) { flag=true; break; } if(temp.a!=a)full(temp,1); if(temp.a!=a&&temp.b)pour(temp,2,1); if(temp.b!=b)full(temp,2); if(temp.b!=b&&temp.a)pour(temp,1,2); if(temp.a)drop(temp,1); if(temp.b)drop(temp,2); front++; } if(flag)print(front); else printf("impossible\n"); } int main() { //freopen("in.txt","r",stdin); while(cin>>a>>b>>c)slove(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator