Codeforces 286E

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
using namespace std; const int maxn=int(1e6)+;
const double eps=0.5;
const double PI=acos(-); struct Complex
{
double real, imag; Complex(double _x=, double _y=):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*];
Complex a[maxn*]; void init()
{
scanf("%d%d", &n, &m);
for (int i=; i<=n; ++i)
{
int num;
scanf("%d", &num);
vis[num]=true;
a[num].real=;
}
}
void init_order()
{
for (int i=; i<wide; ++i)
for (int j=; j<lg; ++j)
rev[i]=(rev[i]<<) | (i>>j & );
}
void FFT(int type)
{
for (int i=; i<wide; ++i)
if (rev[i]>i) swap(a[i], a[rev[i]]); for (int i=; i<=wide; i<<=)
for (int j=; j<wide; j+=i)
{
Complex w(cos(PI*/i), sin(PI*/i*(-type)));
Complex wn(, );
for (int k=; k<i>>; ++k, wn=wn*w)
{
Complex tmp=a[j+k];
a[j+k]=tmp+wn*a[j+k+(i>>)];
a[j+k+(i>>)]=tmp-wn*a[j+k+(i>>)];
}
}
}
void solve()
{
lg=;
while (<<lg<m*) ++lg;
wide=<<lg;
init_order();
FFT();
for (int i=; i<wide; ++i) a[i]=a[i]*a[i];
FFT(-);
for (int i=; 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=; 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=; i<=m; ++i)
if (vis[i] && a[i].real<eps)
ans[++ans[]]=i;
printf("%d\n", ans[]);
for (int i=; i<=ans[]; ++i)
printf("%d ", ans[i]);
}
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
init();
solve();
return ;
}
Codeforces 286E的更多相关文章
- CodeForces 286E Ladies' Shop 多项式 FFT
原文链接http://www.cnblogs.com/zhouzhendong/p/8781889.html 题目传送门 - CodeForces 286E 题意 首先,给你$n$个数(并告诉你$m$ ...
- Codeforces 286E - Ladies' Shop(FFT)
Codeforces 题面传送门 & 洛谷题面传送门 好久没刷过 FFT/NTT 的题了,写篇题解罢( 首先考虑什么样的集合 \(T\) 符合条件.我们考察一个 \(x\in S\),根据题意 ...
- codeforces 286E Ladies' Shop
题目大意:n个小于等于m的数,现在你需要在[1,m]中选择若干个数,使得选出的数能组成的所有数正好与n个数相同,给出最少要选多少个数. 题目分析: 结论一:选择的若干个数一定在n个数中. 证明:否则的 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 1207: C.LU的困惑
题目描述 Master LU 非常喜欢数学,现在有个问题:在二维空间上一共有n个点,LU每连接两个点,就会确定一条直线,对应有一个斜率.现在LU把平面内所有点中任意两点连线,得到的斜率放入一个集合中( ...
- aspx和razor的区别
两者几乎都不懂,现在要选择一种,只能百度,然后一条一条看,也不知道诸位大神哪个说的对. 两个引擎语法完全不一样,性能上Asp.Net略占优势,语法糖则是razor的强项. 开发MVC3首选razor ...
- Nginx安装配置PHP(FastCGI)环境的教程
这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...
- Nginx 变量漫谈(七)
在 (一) 中我们提到过,Nginx 变量的值只有一种类型,那就是字符串,但是变量也有可能压根就不存在有意义的值.没有值的变量也有两种特殊的值:一种是“不合法”(invalid),另一种是“没找到”( ...
- Firebug Command Line
http://michaelsync.net/2007/09/15/firebug-tutorial-commandline-api
- U盘开发之SCSI命令
借助硬件USB协议分析仪,可以清楚的看到U盘启动时和上位机之间交互的USB协议流程,从get desciptor get congfiguration set configuration到scsi命令 ...
- Android的数据存储方式(转)
数据存储在开发中是使用最频繁的,在这里主要介绍Android平台中实现数据存储的5种方式,分别是: 1 使用SharedPreferences存储数据 2 文件存储数据 3 SQLite数据库存储数据 ...
- 关于jqueryUI里的拖拽排序
主要参考http://jsfiddle.net/KyleMit/Geupm/2/ (这个站需要FQ才能看到效果) 其实是jqueryUI官方购物车拖拽添加例子的增强版,就是在拖拽的时候增加了排序 这 ...
- VS2010中更改项目名称(转载)
一.修改解决方案的名称:直接选择解决方案,右键重命名即可.
- ios ViewController present不同的方向
First ViewController CATransition *transition = [CATransition animation]; transition.duration = 0.3; ...