NO
3
//找到状态,并表示,我是以(s,n,m)为状态,之间的倒水关系为边,进行BFS //#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<stack> #include<cstring> #include<queue> #include<algorithm> 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<class T>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<class T> inline void read_(T&x,T&y) { read(x); read(y); } template<class T> 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<class T>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<node> 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<N) { int t=min(N-tmp.n,tmp.s); if(!vis[tmp.s-t][tmp.n+t][tmp.m]) { q.push(node(tmp.s-t,tmp.n+t,tmp.m)); vis[tmp.s-t][tmp.n+t][tmp.m]=vis[tmp.s][tmp.n][tmp.m]+1; } } ///s->m if(tmp.s>0&&tmp.m<M) { int t=min(tmp.s,M-tmp.m); 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; } } ///n->s if(tmp.n>0&&tmp.s<S) { int t=min(tmp.n,S-tmp.s); if(!vis[tmp.s+t][tmp.n-t][tmp.m]) { q.push(node(tmp.s+t,tmp.n-t,tmp.m)); vis[tmp.s+t][tmp.n-t][tmp.m]=vis[tmp.s][tmp.n][tmp.m]+1; } } ///n->m if(tmp.n>0&&tmp.m<M) { int t=min(tmp.n,M-tmp.m); if(!vis[tmp.s][tmp.n-t][tmp.m+t]) { q.push(node(tmp.s,tmp.n-t,tmp.m+t)); vis[tmp.s][tmp.n-t][tmp.m+t]=vis[tmp.s][tmp.n][tmp.m]+1; } } ///m->s if(tmp.s<S&&tmp.m>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<N) { int t=min(tmp.m,N-tmp.n); if(!vis[tmp.s][tmp.n+t][tmp.m-t]) { q.push(node(tmp.s,tmp.n+t,tmp.m-t)); vis[tmp.s][tmp.n+t][tmp.m-t]=vis[tmp.s][tmp.n][tmp.m]+1; } } } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int i,j,k,t; while(~scanf("%d%d%d",&S,&N,&M)&&(S||N||M)) { flag=true; if(S&1){printf("NO\n");continue;} bfs(S,0,0); if(flag)printf("NO\n"); } return 0; }