您的位置:首页 > 其它

3671: [Noi2014]随机数生成器 (贪心)

2014-07-29 22:56 351 查看
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
#define inf 0x7fffffff

inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x*f;
}

const int maxn = 25000005;
long long a, b, c, d;
int x[maxn], t[maxn], n, m, q, top, up[5005], down[5005];

int main() {
memset(up, 127, sizeof (up));
x[0] = read();
a = read();
b = read();
c = read();
d = read();
n = read();
m = read();
q = read();
for (int i = 1; i <= n * m; i++)
x[t[i] = i] = (x[i - 1]*(a * x[i - 1] + b) + c) % d;
for (int i = 1; i <= n * m; i++)
swap(t[i], t[x[i] % i + 1]);
for (int i = 1; i <= q; i++) {
int u = read(), v = read();
swap(t[u], t[v]);
}
for (int i = 1; i <= n * m; i++)
x[t[i]] = i;
for (int i = 1; i <= n * m; i++) {
int xx, yy = x[i] % m;
if (x[i] % m != 0)xx = x[i] / m + 1;
else xx = x[i] / m;
if (!yy)yy += m;
if (yy <= up[xx] && yy >= down[xx]) {
for (int j = 1; j <= n; j++)
if (j < xx)up[j] = min(yy, up[j]);
else if (j > xx)down[j] = max(yy, down[j]);
if (++top == n + m - 1) {
printf("%d", i);
break;
}
printf("%d ", i);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: