USACO Section 3.2 Spinning Wheels - 纯模拟的大水题

USACO Section 3.2 Spinning Wheels - 纯模拟的大水题

主要还是题意~~有点长~感觉确实也讲得不是太清晰... 反正这五个*有那么一个点是相通过去的就ok了...并且要在整数秒时相通..

纯模拟..因为不管速度是多少..反正在360秒后都会转回来...那么就模拟这360秒..每动一秒..判断下有无相通的点...


Program:

/* ID: zzyzzy12 LANG: C++ TASK: spin */ #include<iostream> #include<istream> #include<stdio.h> #include<string.h> #include<math.h> #include<stack> #include<algorithm> #include<queue> #define oo 1000000000 #define ll long long using namespace std; struct node { int speed,num,s[6][3]; }a[6]; int i,j; void getanswer() { int p,k,t,have[380]; for (p=0;p<360;p++) { memset(have,0,sizeof(have)); for (i=1;i<=5;i++) for (j=1;j<=a[i].num;j++) { k=(a[i].s[j][0]+p*a[i].speed)%360; t=(k+a[i].s[j][1])%360; while (k!=t) { have[k]++; k++; if (k==360) k=0; } have[t]++; } for (i=0;i<360;i++) if (have[i]==5) { printf("%d\n",p); return; } } printf("none\n"); return; } int main() { freopen("spin.in","r",stdin); freopen("spin.out","w",stdout); for (i=1;i<=5;i++) { scanf("%d%d",&a[i].speed,&a[i].num); for (j=1;j<=a[i].num;j++) scanf("%d%d",&a[i].s[j][0],&a[i].s[j][1]); } getanswer(); return 0; }