Prioritize the processing of arrays in the way it describes
And then, in order to get as many small numbers as possible in the sequence,
So 1 is a must to appear, in order to make the whole sequence of the order of the dictionary after the smallest.
We thought, if 2 could be in this series, it'd be better.
But 2 may not be in this series, that is, 2 walk 1 is impossible to go to the place, you can not walk 2.
So from small to large enumeration numbers, if the current number can go, the output, and then mark all the nodes that go out of this node can not go.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std; typedef long Long LL; #define N 5010 LL seed,a,b,c,d; int n,m,ask;int x, y; int Arr[n*n],g[n][n];int ans[n<<2]; BOOL V[n][n]; int work () {return seed= (a*seed*seed%d+b*seed%d+c)%d;} int main () {scanf ("%lld%lld%lld%lld%lld%d%d%d", &seed,& ; a,&b,&c,&d,&m,&n,&ask); for (int i=1;i<=n*m;i++) Arr[i]=i,swap (Arr[i],arr[work ()%i+1]); for (int i=1;i<=ask;i++) {scanf ("%d%d", &x,&y); Swap (arr[x],arr[y]); } for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) g[i][j]=arr[(i-1) *n+j]; for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) arr[g[i][j]]= (i-1) *n+j; for (int i=1;i<=n*m;i++) {x=arr[i]/n+1-(arr[i]%n==0); y=arr[i]-(x-1) *n; if (!v[x][y]) {if (i!=1) Putchar ("); printf ("%d", I); for (int j=x+1;j<=m;j++) for (int k=y-1;k;k--) {if (V[j][k]) Break V[j][k]=true; } for (int j=x-1;j;j--) for (int k=y+1;k<=n;k++) {if (V[j][k]) break; V[j][k]=true; }}} return 0;}
"bzoj3671" [Noi2014] random number generator