题意:求一个最小的数seed,使得一个非负整数S的所有元素模上seed后形成的可重集合S1没有重复元素
正解为FFT,但我不会。。。但时候再来补FFT版
假解析:元素s=k*seed+p,0=<p<seed,即p有seed种,所以可知seed的最小值即为sizeof(S),最大值易知为max(s)+1,即S1=S
如上所说,大部分能过多亏数据比较水,本蒟蒻就写蒟蒻解法:暴力假算法就当不存在吧
AcCode:
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 500010;
int n, rmax = -1;
int arr[N];
bool vis[N];
vector<int> vec;
signed main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &arr[i]), rmax = (rmax > arr[i]) ? rmax : arr[i], vis[arr[i]] = 1;
sort(arr + 1, arr + 1 + n);
for (int ans = n; ans <= rmax; ans++) {
int index = lower_bound(arr + 1, arr + 1 + n, ans) - (arr);
bool sign = true;
for (int i = index; i <= n; i++) {
if (vis[arr[i] % ans]) {
sign = false;
break;
}
vis[arr[i] % ans] = true;
vec.push_back(arr[i] % ans);
}
if (sign) {
printf("%d\n", ans);
return 0;
}
while (!vec.empty()) {
vis[vec.back()] = false;
vec.pop_back();
}
}
printf("%d\n", rmax + 1);
}