Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 24840 Accepted Submission (s): 9666
Problem description Everyone must feel the exercise after drinking Coke is a very pleasant thing, but seeyou don't think so. Because every time when Seeyou bought Coke, Ox asked to share this bottle of Coke with seeyou, and must drink as much as seeyou. But Seeyou's hands only two cups, their capacity is N ml and M ml cola volume for S (s<101) ml (just fill a bottle), they can pour coke between three each other (there is no scale, and s==n+m,101>s>0,n>0,m>0). Smart Acmer, do you think they can split it? If you can output the minimum number of Coke, if you cannot output "no".
Input three integers: the volume of S Cola, N and M is the capacity of two cups, ending with "0 0 0".
Output if it can be divided into a minimum number of times to pour, otherwise output "NO".
Sample Input7 4 34 1 30 0 0
Sample OutputNO3
Authorseeyou
Source "2006 Campus cultural activity Month" of "School Anniversary Cup" College students Program Design Competition and Hangzhou University of Engineering fourth session of college students Program design contest
Recommendll | We have carefully selected several similar problems for you:1175 1253 1072 1372 11,801 at first, I wanted to find the best answer by thinking, finding it difficult, so we had to go through all the situations. , find the minimum number of steps, similar to the shortest path of the two-dimensional diagram, BFS traversal in various cases, when found out which cup or bottle has S/2 Cola can output the answer, but the request is to get two s/2 answer, that is, a cup must be empty, so the answer to return to determine whether there is empty, If not, you need to add one more step to complete. Here a 3-element array instead of S,n,m,order is a sequential array, i.e. order[i][0] is inverted in order[i][1], order[i][2] remains the same. In the case of access, we map records, that is, the check function. Code:
#include <iostream>#include<cstdio>#include<cstring>#include<queue>using namespacestd;structSTA {intar[3]; STA () {} sta (intAintBintc) {ar[0] =A; ar[1] =b; ar[2] =C; }};typedef pair<sta,int>PA;intar[3];intorder[6][3] = {0,1,2,0,2,1,1,0,2,1,2,0,2,0,1,2,1,0};BOOLvis[1000001];BOOLCheckConstSTA &temp) { intD = temp.ar[0] *10000+ temp.ar[1] * -+ temp.ar[2]; BOOLE =Vis[d]; VIS[D]=true; returne;} STA Change (ConstSTA &temp,intAintBintc) {STA temp1; if(Temp.ar[a] > Ar[b]-Temp.ar[b]) {Temp1.ar[a]= Temp.ar[a]-ar[b] +Temp.ar[b]; TEMP1.AR[B]=Ar[b]; } Else{Temp1.ar[a]=0; TEMP1.AR[B]= Temp.ar[b] +Temp.ar[a]; } Temp1.ar[c]=Temp.ar[c]; returnTemp1;}intBFs () {if(ar[0] %2)return 0; Queue<pa>Q; Q.push (PA (STA (ar[0],0,0),0)); Check (STA (ar[0],0,0)); while(!Q.empty ()) {STA temp=Q.front (). First,temp1; intTimes =Q.front (). Second; Q.pop (); for(inti =0; I <6; i + +) {Temp1= Change (temp,order[i][0],order[i][1],order[i][2]); if(temp1.ar[0] = = ar[0] /2|| temp1.ar[1] = = ar[0] /2|| temp1.ar[2] = = ar[0] /2)returnTimes +1+ (temp1.ar[0] && temp1.ar[1] && temp1.ar[2]); if(!check (TEMP1)) Q.push (PA (temp1,times +1)); } } return 0;}intMain () { while(SCANF ("%d%d%d", &ar[0],&ar[1],&ar[2]) && ar[0] && ar[1] && ar[2]) {memset (Vis,false,sizeof(VIS)); intAns =BFS (); if(ANS) printf ("%d\n", ans); Elseprintf"no\n"); }}
Hdu 1495 very Coke