There are five opaque discs with no more than five sector notches on each disc, and the five discs overlap, each with a fixed speed rotation, asking how long the light can pass through the discs.
World simulation problem, but at the beginning has been tangled how to judge the state has been enumerated, that is, the problem of weighing, later learned not to judge the weight, when the number of rotations more than 360 times, will return to the starting state.
/*id:modengd1prog:spinlang:c++*/#include <iostream> #include <stdio.h>using namespace std;struct wheel{I NT speed; int hole; int sta[5],end[5];}; Wheel Wheel[5];bool Ispass () {int passcounter; for (int i=0;i<360;i++) {passcounter=0; for (int j=0;j<5;j++) {for (int k=0;k<wheel[j].hole;k++) {if (i==270) i=270; if (Wheel[j]. STA[K]<=WHEEL[J]. END[K]&&I>=WHEEL[J]. STA[K]&&WHEEL[J]. end[k]>=i) {passcounter++; Break } if (Wheel[j]. STA[K]>WHEEL[J]. end[k]&& (I>=wheel[j]. sta[k]| | WHEEL[J]. end[k]>=i)) {passcounter++; Break }}} if (passcounter==5) return true; } return false;} int main () {freopen ("spin.in", "R", stdin); Freopen ("Spin.out"," W ", stdout); input for (int i=0;i<5;i++) {scanf ("%d%d", &wheel[i].speed,&wheel[i].hole); for (int j=0;j<wheel[i].hole;j++) {scanf ("%d%d", &wheel[i]. Sta[j],&wheel[i]. END[J]); Wheel[i]. End[j]= (Wheel[i]. End[j]+wheel[i]. STA[J])%360; }}//rotate for (int i=0;i<360;i++) {if (Ispass ()) {cout<<i<<endl; return 0; } for (int j=0;j<5;j++) {for (int k=0;k<wheel[j].hole;k++) {Wheel [j]. Sta[k]= (Wheel[j]. Sta[k]+wheel[j].speed)%360; WHEEL[J]. End[k]= (Wheel[j]. End[k]+wheel[j].speed)%360; }}} cout<< "None" <<endl; return 0;}
Usaco Spinning Wheels