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; }
相关文章推荐
- BZOJ 3671 NOI 2014 随机数生成器 贪心
- [BZOJ3671][Noi2014]随机数生成器 && 贪心
- [贪心] BZOJ 3671 [Noi2014]随机数生成器
- [bzoj3671][Noi2014][随机数生成器] (贪心+位运算+卡空间)
- BZOJ_3671_[Noi2014]随机数生成器_set+贪心
- BZOJ 3671 NOI2014 随机数生成器 贪心+暴力
- 贪心 BZOJ 3671:[Noi2014]随机数生成器
- 【bzoj3671】[Noi2014]随机数生成器 贪心
- 【BZOJ3671】[Noi2014]随机数生成器【模拟】【贪心】【卡空间】
- [BZOJ 3671][Noi2014]随机数生成器:贪心
- BZOJ3671 NOI2014随机数生成器 贪心+暴力
- 【BZOJ3671】【NOI2014】随机数据生成器(贪心)
- 【BZOJ3671】【NOI2014】随机数据生成器(贪心)
- BZOJ 3671 NOI2014 随机数生成器
- 3671: [Noi2014]随机数生成器
- BZOJ 3671 [NOI2014 D2T2] 随机数生成器
- [NOI 2014] 随机数生成器:模拟,贪心
- BZOJ3671 [Noi2014]随机数生成器 【贪心】
- [BZOJ3671][Noi2014]随机数生成器
- 【BZOJ3671】【UOJ6】【NOI2014】随机数生成器