django企业网站源码,合肥医疗网站建设,西安网站建设那家强,高端的佛山网站建设大家一定觉的运动以后喝可乐是一件很惬意的事情#xff0c;但是seeyou却不这么认为。因为每次当seeyou买了可乐以后#xff0c;阿牛就要求和seeyou一起分享这一瓶可乐#xff0c;而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子#xff0c;它们的容量分别是N 毫…大家一定觉的运动以后喝可乐是一件很惬意的事情但是seeyou却不这么认为。因为每次当seeyou买了可乐以后阿牛就要求和seeyou一起分享这一瓶可乐而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子它们的容量分别是N 毫升和M 毫升 可乐的体积为S S101毫升 (正好装满一瓶) 它们三个之间可以相互倒可乐 (都是没有刻度的且 SNM101S0N0M0) 。聪明的ACMER你们说他们能平分吗如果能请输出倒可乐的最少的次数如果不能输出NO。 Input三个整数 : S 可乐的体积 , N 和 M是两个杯子的容量以0 0 0结束。Output如果能平分的话请输出最少要倒的次数否则输出NO。Sample Input
7 4 3
4 1 3
0 0 0
Sample Output
NO
3 #includeiostream
#includequeue
#includecstdio
#includecstring
using namespace std;
#define MAX 105
#define true 1
#define false 0
#define overflow -2
int s,n,m;
bool vis[MAX][MAX][MAX];struct point
{int s,n,m;int step;
};int bfs()
{if(s%21)return overflow;int s2s/2;queuepointq;struct point t;t.ss;t.n0;t.m0;t.step0;q.push(t);vis[s][0][0]false;while(!q.empty()){tq.front();//coutt.s t.n t.m t.stependl;if((t.st.nt.ss2)||(t.st.mt.ss2)||(t.nt.mt.ns2)){return t.step;}q.pop();struct point w;if(t.sn-t.n0){if(t.sn-t.n){w.st.s-(n-t.n);w.nn;w.mt.m;}else{w.s0;w.nt.nt.s;w.mt.m;}if(vis[w.s][w.n][w.m]){vis[w.s][w.n][w.m]false;w.stept.step1;q.push(w);}}if(t.sm-t.m0){if(t.sm-t.m){w.st.s-(m-t.m);w.mm;w.nt.n;}else{w.s0;w.mt.mt.s;w.nt.n;}if(vis[w.s][w.n][w.m]){vis[w.s][w.n][w.m]false;w.stept.step1;q.push(w);}}if(t.ns-t.s0){if(t.ns-t.s){w.nt.n-(s-t.s);w.ss;w.mt.m;}else{w.n0;w.st.nt.s;w.mt.m;}if(vis[w.s][w.n][w.m]){vis[w.s][w.n][w.m]false;w.stept.step1;q.push(w);}}if(t.nm-t.m0){if(t.nm-t.m){w.nt.n-(m-t.m);w.mm;w.st.s;}else{w.n0;w.mt.nt.m;w.st.s;}if(vis[w.s][w.n][w.m]){vis[w.s][w.n][w.m]false;w.stept.step1;q.push(w);}}if(t.ms-t.s0){if(t.ms-t.s){w.mt.m-(s-t.s);w.ss;w.nt.n;}else{w.m0;w.st.mt.s;w.nt.n;}if(vis[w.s][w.n][w.m]){vis[w.s][w.n][w.m]false;w.stept.step1;q.push(w);}}if(t.mn-t.n0){if(t.mn-t.n){w.mt.m-(n-t.n);w.nn;w.st.s;}else{w.m0;w.nt.nt.m;w.st.s;}if(vis[w.s][w.n][w.m]){vis[w.s][w.n][w.m]false;w.stept.step1;q.push(w);}}}return -1;
}int main()
{while(scanf(%d%d%d,s,n,m)){if(s0n0m0)break;memset(vis,true,sizeof(vis));int cbfs();if(c0)coutNOendl;else coutcendl;}
}