The question is very long, and it means the transfer of the ball.
Three tracks, one database. It is the track in minutes, the track in 5 minutes, the track in one hour, and the database with N capacity. Every minute, a small ball comes out of the database. The database conforms to the first-in-first-out mode and enters the minute track. If there are already four in the minute track, the four are slide into the database, the ball enters the 5-minute track. If there are 11 5-minute tracks, the 11 will slide into the database, and the ball will slide into the hour track, if there are already 11 hourly tracks, these 11 are slide into the database, and the ball is finally slide into the database. When the ball in the track is slide into the database, the ball in the track is ready to go first and then out. In this case, the track is the stack, and the database is the queue. And the simulation process has also come out. Brute force attacks
This question
Improved my debugging capability.
1. Use freopen input and output for large-scale data, compare diff with UE and other software, locate the problem, and debug it.
2. Set conditional output in the middle.
#include <iostream>#include <cstdio>#include <vector>#include <string>#define maxn 1005using namespace std;int N,M;int a[200];int q[60*24*10];int Mstack[3][20];//sec min houint top[3];int vis[200];int head,tail;int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int solve(){int i,j,k,flag;int cnt,ans;for(i=1;i<=N;i++)q[i]=a[i]=i;head=1;tail=N+1;memset(top,0,sizeof(top));memset(vis,0,sizeof(vis));for(j=tail,i=1;i<=60*24;i++){if(top[0]==4){for(k=0;k<4;k++) q[j++]=Mstack[0][--top[0]];if(top[1]==11){for(k=0;k<11;k++) q[j++]=Mstack[1][--top[1]];if(top[2]==11){for(k=0;k<11;k++) q[j++]=Mstack[2][--top[2]];q[j++]=q[i];}elseMstack[2][top[2]++]=q[i];}elseMstack[1][top[1]++]=q[i];}elseMstack[0][top[0]++]=q[i];/*if(i>=720)printf("%d\n",q[i]);printf("\n");*/}ans=1;for(j=i;j<N+i;j++){if(vis[j-i+1]==0){vis[j-i+1]=1;k=q[j];cnt=1;while(vis[k]==0){cnt++;vis[k]=1;k=q[i+k-1];}ans=ans/gcd(ans,cnt)*cnt;}}return ans;}int main(){//freopen("E:\\out.txt","w",stdout); while(scanf("%d",&N),N) {printf("%d balls cycle after %d days.\n",N,solve());} return 0;}
Poj 1879 Tempus et mobilius time and motion (simulation + group)