[LINK] I am a link. Click me :)
Question]
[Question]
It is good to simulate one unit time and one unit time.
Then for everyone.
Record its cycle subscript idx
Every unit of time will let everyone's idx ++
Pay attention to the processing of the line from waking to sleep.
It can be repeated several times .. No solution is considered if the limit is exceeded
(Other solutions also provide a method, that is, if the status is the same as the initial situation. A ring is formed without any solution.
(If there is no solution, it will definitely form a ring?
[Code]
#include <bits/stdc++.h>#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)using namespace std;const int N = 10;int n;int a[N+10][N+10];int cur[N+10],tot[N+10];int main(){ //freopen("D:\\rush.txt","r",stdin); ios::sync_with_stdio(0),cin.tie(0); int kase = 0; while (cin >> n){ if (n==0) break; rep1(i,1,n){ int x,y; cin >> x >> y >> cur[i];cur[i]--; rep1(j,1,x) a[i][j-1] = 1; rep1(j,x+1,x+y) a[i][j-1] = 2; tot[i] = x+y; } cout<<"Case "<<++kase<<": "; rep1(kk,1,10000){ int sleep = 0,wake = 0; rep1(i,1,n){ if (a[i][cur[i]]==1) wake++;else sleep++; } if (sleep==0){ cout<<kk<<endl; break; } rep1(i,1,n){ if (a[i][cur[i]]==1 && a[i][(cur[i]+1)%tot[i]]==2){ if (sleep>wake){ cur[i] = (cur[i]+1)%tot[i]; }else{ cur[i] = 0; } }else{ cur[i] = (cur[i]+1)%tot[i]; } } } int sleep = 0; rep1(i,1,n) if (a[i][cur[i]]==2) sleep++; if (sleep>0) cout<<-1<<endl; } return 0;}
[Exercise 4-8 UVA-12108] extraordinarily tired students