bzoj 3771 Triple FFT 生成函数+容斥
Triple
Time Limit: 20 Sec Memory Limit: 64 MB
Submit: 847 Solved: 482
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
4
5
6
7
Sample Output
5 1
6 1
7 1
9 1
10 1
11 2
12 1
13 1
15 1
16 1
17 1
18 1
样例解释
11有两种方案是4+7和5+6,其他损失值都有唯一方案,例如4=4,5=5,10=4+6,18=5+6+7.
HINT
所有数据满足:Ai<=40000
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm> #define pi acos(-1)
#define N 40007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,num,L;
int rev[N*];
struct comp
{
double r,v;
comp(){r=v=0.0;}
comp(double x,double y){r=x,v=y;}
friend inline comp operator+(comp x,comp y){return comp(x.r+y.r,x.v+y.v);}
friend inline comp operator-(comp x,comp y){return comp(x.r-y.r,x.v-y.v);}
friend inline comp operator*(comp x,comp y){return comp(x.r*y.r-x.v*y.v,x.r*y.v+x.v*y.r);}
friend inline comp operator/(comp x,int y){return comp(x.r/y,x.v/y);}
}a[N*],b[N*],c[N*]; void FFT(comp *a,int flag)
{
for (int i=;i<num;i++)
if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int i=;i<num;i<<=)
{
comp wn=comp(cos(pi/i),flag*sin(pi/i));
for (int j=;j<num;j+=(i<<))
{
comp w=comp(,);
for (int k=;k<i;k++,w=w*wn)
{
comp x=a[j+k],y=w*a[j+k+i];
a[j+k]=x+y,a[j+k+i]=x-y;
}
}
}
if (flag==-) for (int i=;i<num;i++) a[i].r/=num;
}
int main()
{
n=read();int up=;
for (int i=;i<=n;i++)
{
int x=read();
a[x].r+=1.0;
b[x*].r+=1.0;
c[x*].r+=1.0;
up=max(up,x*);
}
for (num=;num<=up;num<<=,L++);if (L) L--;
for (int i=;i<num;i++) rev[i]=(rev[i>>]>>)|((i&)<<L);
FFT(a,),FFT(b,),FFT(c,);
for (int i=;i<num;i++)
a[i]=a[i]+a[i]*a[i]/-b[i]/+a[i]*a[i]*a[i]/-a[i]*b[i]/+c[i]/;
FFT(a,-); for (int i=;i<num;i++)
{
int x=(int)(a[i].r+0.5);
if (x==) continue;
printf("%d %d\n",i,x);
}
}
bzoj 3771 Triple FFT 生成函数+容斥的更多相关文章
- [BZOJ 3771] Triple(FFT+容斥原理+生成函数)
[BZOJ 3771] Triple(FFT+生成函数) 题面 给出 n个物品,价值为别为\(w_i\)且各不相同,现在可以取1个.2个或3个,问每种价值和有几种情况? 分析 这种计数问题容易想到生成 ...
- BZOJ 3771: Triple(FFT+容斥)
题面 Description 我们讲一个悲伤的故事. 从前有一个贫穷的樵夫在河边砍柴. 这时候河里出现了一个水神,夺过了他的斧头,说: "这把斧头,是不是你的?" 樵夫一看:&qu ...
- BZOJ 3771 Triple FFT+容斥原理
解析: 这东西其实就是指数型母函数? 所以刚开始读入的值我们都把它前面的系数置为1. 然后其实就是个多项式乘法了. 最大范围显然是读入的值中的最大值乘三,对于本题的话是12W? 用FFT优化的话,达到 ...
- bzoj 3771: Triple【生成函数+FFT+容斥原理】
瞎搞居然1A,真是吃鲸 n的范围只有聪明人能看见--建议读题3遍 首先看计数就想到生成函数,列出多项式A(x),然后分别考虑123 对于选一个的直接计数即可: 对于选两个的,\( A(x)^2 \), ...
- bzoj 3771 Triple——FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3771 把方案作为系数.值作为指数,两项相乘就是系数相乘.指数相加,符合意义. 考虑去重.先自 ...
- bzoj 3771 Triple —— FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3771 令多项式的系数是方案数,次数是值: 设 a(x) 为一个物品的多项式,即 a[w[i] ...
- BZOJ 3771 Triple ——FFT
直接暴力卷积+统计就可以了. 去重比较复杂. 其实也不复杂,抄吧! 反正AC了. #include <map> #include <cmath> #include <qu ...
- 【BZOJ 3771】 3771: Triple (FFT+容斥)
3771: Triple Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 547 Solved: 307 Description 我们讲一个悲伤的故事. ...
- BZOJ 3771: Triple(生成函数 FFT)
Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 911 Solved: 528[Submit][Status][Discuss] Description ...
随机推荐
- 008---re正则模块
re正则模块 字符串的匹配规则 匹配模式 re.match() re.search() re.findall() re.split() re.sub() 元字符 print('------------ ...
- 【Leetcode】413. Arithmetic Slices
Description A sequence of number is called arithmetic if it consists of at least three elements and ...
- ULINE(插入水平线)
WRITE 'This is Underlined'. ULINE. 输出结果: This is Underlined. ———————————————————
- python linecache读取过程
最近使用Python编写日志处理脚本时,对Python的几种读取文件的方式进行了实验.其中,linecache的行为引起了我的注意. Python按行读取文件的经典方式有以下几种: with open ...
- 人工智能,图片识别,与GUI编程
GUI编程: https://sourceforge.net/projects/pyqt/ 百度aip图片识别 https://pypi.python.org/pypi/baidu-aip
- malloc分配失败的两个现象
在实际代码中,malloc的反复分配释放,可能会导致某一次malloc分配失败,虽然上一次调用malloc分配成功(然后释放),下一次在相同地方调用malloc分配可能会失败,疑问在于,既然上一次分配 ...
- awk用法介绍
Awk 程序的结构如下: awk 'BEGIN{ print "start" } pattern { commands } END{ print "end" } ...
- Windows2008新建域时Administrator 帐户密码不符合要求
Windows 2008 系统安装完毕后,(环境:在安装的时间,系统没有设置密码.做好系统后,进入制面板添加了密码或按ctrl + alt + del 设置密码后 在服务器管理-角色 ...
- Yarn 命令详解
常用命令 创建项目:yarn init 安装依赖包:yarn == yarn install 添加依赖包:yarn add 配置淘宝镜像:yarn config set registry " ...
- Qt Demo Http 解析网址 Openssl
今天练习了一下Qt 解析http协议,在Demo中使用到了Openssl 一上午的时间都是编译openssl,不过还是没有成功,很遗憾,这里整理了有关这个Demo的本件 网盘连接:见下方评论吧,长传太 ...