首页 > 代码库 > Codeforces 444B DZY Loves FFT(概率)
Codeforces 444B DZY Loves FFT(概率)
题目连接:Codeforces 444B DZY Loves FFT
题目大意:根据题目的算法生成a,b数组,然后对于每个长度的l,求a[i]*b[l-i]的最大值。
解题思路:概率问题,枚举前30大的数,如果有就可以直接输出答案,如果没有,就暴力枚举b数组为1的位置找最大值。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
const int s = 30;
int n, d, x, rec[maxn+5];
int np, pos[maxn+5];
int a[maxn+5], b[maxn+5];
int get_next () {
return x = (37LL * x + 10007) % 1000000007;
}
void init_table () {
for (int i = 0; i < n; i++)
a[i] = i + 1;
for (int i = 0; i < n; i++)
swap(a[i], a[get_next() % (i+1)]);
for (int i = 0; i < n; i++)
b[i] = (i < d ? 1 : 0);
for (int i = 0; i < n; i++)
swap(b[i], b[get_next() % (i+1)]);
}
void init_pos () {
np = 0;
for (int i = 0; i < n; i++) {
if (b[i])
pos[np++] = i;
}
for (int i = 0; i < n; i++)
rec[a[i]] = i;
}
int main () {
scanf("%d%d%d", &n, &d, &x);
init_table();
init_pos();
for (int i = 0; i < n; i++) {
bool flag = true;
for (int j = n; j >= n-s; j--) {
if (rec[j] <= i && b[i-rec[j]]) {
flag = false;
printf("%d\n", j);
break;
}
}
if (flag) {
int ans = 0;
for (int j = 0; j < np && pos[j] <= i; j++) {
ans = max(ans, a[i-pos[j]]);
}
printf("%d\n", ans);
}
}
return 0;
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。