NO
3
//找到狀態,並表示,我是以(s,n,m)為狀態,之間的倒水關系為邊,進行BFS //#include#include #include #include #include #include #include #include using namespace std; const int maxn=105; const int inf=200000; #define lson rt<<1,l,m #define rson rt<<1|1,m+1,r #define For(i,n) for(int i=0;i<(n);i++) template inline T read(T&x) { char c; while((c=getchar())<=32); bool ok=false; if(c=='-')ok=true,c=getchar(); for(x=0; c>32; c=getchar()) x=x*10+c-'0'; if(ok)x=-x; return x; } template inline void read_(T&x,T&y) { read(x); read(y); } template inline void write(T x) { if(x<0)putchar('-'),x=-x; if(x<10)putchar(x+'0'); else write(x/10),putchar(x%10+'0'); } template inline void writeln(T x) { write(x); putchar('\n'); } // -------IO template------ struct node { int s,n,m; node(int a,int b,int c) { s=a;n=b;m=c; } }; int N,M,S; bool ok(node a) { int cnt=0; if(a.s==S/2) cnt++; if(a.n==S/2) cnt++; if(a.m==S/2) cnt++; if(cnt>=2)return true; return false; } int vis[maxn][maxn][maxn]; bool flag=0; void bfs(int s,int n,int m) { queue q; q.push(node(s,n,m)); vis[s][n][m]=1; memset(vis,0,sizeof(vis)); while(!q.empty()) { node tmp=q.front();q.pop(); // printf("%d %d %d\n",tmp.s,tmp.n,tmp.m); if(ok(tmp)) { printf("%d\n",vis[tmp.s][tmp.n][tmp.m]); flag=false; return ; } ///s->n if(tmp.s>0&&tmp.n m if(tmp.s>0&&tmp.m s if(tmp.n>0&&tmp.s m if(tmp.n>0&&tmp.ms if(tmp.s 0) { int t=min(tmp.m,S-tmp.s); if(!vis[tmp.s+t][tmp.n][tmp.m-t]) { q.push(node(tmp.s+t,tmp.n,tmp.m-t)); vis[tmp.s+t][tmp.n][tmp.m-t]=vis[tmp.s][tmp.n][tmp.m]+1; } } ///m->n if(tmp.m>0&&tmp.n