Test instructions is to give you five wheels, each wheel has some openings, now each wheel from 0 position began to turn, ask the shortest time 5 wheel openings meet, just start to see this problem when there is no idea, like wait until the last in writing, and finally did not think of the solution, direct simulation on the line, the code is as follows: (attention to processing boundaries He is not a discrete 360 mouth, but an interval.
/*id:m1500293 lang:c++ Prog:spin*/#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;BOOLwhell[6][390];intw[5];intidx[5] = {0,0,0,0,0};intCheck () { for(intI=0; i< the; i++) { BOOLres =true; for(intj=0; j<5; J + +) {res= res&whell[j][(idx[j]+i)% the]; } if(RES)return true; } return false;}intMain () {Freopen ("spin.in","R", stdin); Freopen ("Spin.out","W", stdout); memset (Whell,0,sizeof(Whell)); for(intI=0; i<5; i++) {scanf ("%d", &W[i]); intT; scanf ("%d", &t); for(intj=0; j<t; J + +) { intSt, WI; scanf ("%d%d", &st, &WI); for(intk=st; k<=st+wi; k++) Whell[i][k% the] =1; } } for(intI=0; i< the; i++) {if(check ()) {printf ("%d\n", i); return 0; } for(intj=0; j<5; J + +) {Idx[j]= ((Idx[j]-w[j])% the+ the)% the; Note that there may be a negative number, WA once}} printf ("none\n");}
)
Usaco Spinning Wheels