您的位置:首页 > 其它

Codeforces 286E

2015-12-18 20:25 155 查看
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
using namespace std;

const int maxn=int(1e6)+100;
const double eps=0.5;
const double PI=acos(-1);

struct Complex
{
double real, imag;

Complex(double _x=0, double _y=0):real(_x), imag(_y) {}

Complex operator + (Complex b)
{
return Complex(real+b.real, imag+b.imag);
}

Complex operator - (Complex b)
{
return Complex(real-b.real, imag-b.imag);
}

Complex operator * (Complex b)
{
return Complex(real*b.real-imag*b.imag, real*b.imag+b.real*imag);
}
};

int n, m;
int lg, wide;
bool vis[maxn];
int ans[maxn], rev[maxn*8];
Complex a[maxn*8];

void init()
{
scanf("%d%d", &n, &m);
for (int i=1; i<=n; ++i)
{
int num;
scanf("%d", &num);
vis[num]=true;
a[num].real=1;
}
}
void init_order()
{
for (int i=0; i<wide; ++i)
for (int j=0; j<lg; ++j)
rev[i]=(rev[i]<<1) | (i>>j & 1);
}
void FFT(int type)
{
for (int i=0; i<wide; ++i)
if (rev[i]>i) swap(a[i], a[rev[i]]);

for (int i=2; i<=wide; i<<=1)
for (int j=0; j<wide; j+=i)
{
Complex w(cos(PI*2/i), sin(PI*2/i*(-type)));
Complex wn(1, 0);
for (int k=0; k<i>>1; ++k, wn=wn*w)
{
Complex tmp=a[j+k];
a[j+k]=tmp+wn*a[j+k+(i>>1)];
a[j+k+(i>>1)]=tmp-wn*a[j+k+(i>>1)];
}
}
}
void solve()
{
lg=0;
while (1<<lg<m*2) ++lg;
wide=1<<lg;
init_order();
FFT(1);
for (int i=0; i<wide; ++i) a[i]=a[i]*a[i];
FFT(-1);
for (int i=0; i<wide; ++i) a[i].real/=wide;
/*
for (int i=0; i<wide; ++i)
printf("%d ", int(a[i].real+0.5));
*/
bool flag=true;
for (int i=0; i<=m; ++i)
if (a[i].real>eps && !vis[i])
{
flag=false;
break;
}
if (!flag) printf("NO\n");
else
{
printf("YES\n");
for (int i=0; i<=m; ++i)
if (vis[i] && a[i].real<eps)
ans[++ans[0]]=i;
printf("%d\n", ans[0]);
for (int i=1; i<=ans[0]; ++i)
printf("%d ", ans[i]);
}
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
init();
solve();
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: