2054: Crazy steamed bread time limit:10 Sec Memory limit:162 MB
submit:449 solved:175
[Submit] [Status] Description
Input
First row four positive integers n,m,p,q
Output
A total of n lines are output, and line I represents the final color of the steamed bun (if the final color is white, the output is 0).
Sample Input4 3 2 4Sample Output2
2
3
0HINT
Using and looking for a set of AH ah ah ah ah ah ah ah ah ah
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath >using namespace Std;int n,fa[1000010],m,p,q,col[1000010];int Find (int x) { return X==fa[x]?x:fa[x]=find (Fa[x] );} int main () { int tot=0; scanf ("%d%d%d%d", &n,&m,&p,&q); for (int i=1;i<=n;i++) fa[i]=i; for (int i=m;i>=1;i--) { int l,r; L= ((long) i*p+q)%n+1,r= ((Long Long) i*q+p)%n+1; if (l>r) swap (l,r); for (int k=find (l); K<=r;k=find (k)) { col[k]=i; tot++; fa[k]=k+1; } if (tot==n) break ; } printf ("%d", col[1]); for (int i=2;i<=n;i++) printf ("%d", Col[i]); printf ("\ n"); return 0;}
(interval operation) Bzoj 2054