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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- windows10快捷键
• 贴靠窗口:Win +左/右> Win +上/下>窗口可以变为1/4大小放置在屏幕4个角落 • 切换窗口:Alt + Tab(不是新的,但任务切换界面改进) • 任务视图:Win + ...
- 程序A+B问题(一次输入和多次输入)
这是早就会写的题,把它整理一下,比较容易. ➀一次输入数据,计算A+B #include<stdio.h> #include<stdlib.h> int main() { ...
- UIButton控件
UIButton继承关系如下: UIButton-->UIControl-->UIView-->UIResponder-->NSObject 由于继承层次过多,下面只重点介绍U ...
- linux下维护服务器之常用命令
linux下维护服务器之常用命令! 第1套如下: 正则表达式: 1.如何不要文件中的空白行和注释语句: [root@localhost ~]# grep -v '^$' 文件名 |grep -v '^ ...
- fstab 介绍
http://forum.ubuntu.org.cn/viewtopic.php?t=58468 主要翻译自http://www.tuxfiles.org/linuxhelp/fstab.html,根 ...
- IT技术 | 让程序员抓狂的排序算法教学视频
点击「箭头所指处」可快速关注传智特刊微信号:CZTEKAN 原文地址:http://mp.weixin.qq.com/s?__biz=MjM5OTM4NDMyMg==&mid=20056820 ...
- 2.5 Local Methods in High Dimensions
curse of dimensionality 输入在p维立方体中符合均匀分布,如果需要覆盖比例r的体积,需要每个维度上\(e_p(r)=r^{1/p}\) \(e_{10}(0.01)=0.63,e ...
- 打包静态库.a文件的方法(ar,ranlib,nm命令介绍)
一 常用脚本 1 打包脚本 脚本如下,下面附上ar 和 ranlib命令参考(命令来自于网络) ALLLIB=*.aFILE=`ls *.a`#原来的库解压重命名 for F in $FILEdo ...
- Baby Ming and Matrix games(dfs计算表达式)
Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- poj 3255 求次大最短路
Roadblocks Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5508 Accepted: 2088 Descri ...