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
相关文章推荐
- 《高性能HTML5》读后整理的Web性能优化内容
- 10 导航控制器UINavigationController、导航条navigationBar、界面通信(属性传值、代理传值、单例传值)
- 防止sql注入
- Codeforces 339E
- 分布式计算,大型网站技术架构:核心原理与案例分析
- 分布式计算,大型网站技术架构:核心原理与案例分析
- 上楼梯问题
- 分布式计算,大型网站技术架构:核心原理与案例分析
- Apache Hadoop新版本的特性
- 虚拟化三剑客专题-XenServer(下)
- Java 异常处理
- Javascript 那些事-开篇
- Android开发环境的搭建之(三)虚拟设备AVD的创建
- Squares - poj 2002(hash)
- UIAlertView与UIActionSheet
- ArcGIS JavaScript API 4.0 beta3 新特性
- javascript 涉及float的精确加减乘除运算
- AndroidStudio基础视频教程-整理
- linux打开文件数量的查看方法
- iOS SQLite如何连续插入多行数据