UVA 12298 Super Poker II (FFT)
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; const int N = 1000005;
const long double pi = acos(-1.0); struct Complex
{
long double r,i;
Complex(long double r=0, long double i=0):r(r),i(i) {};
Complex operator+(const Complex &rhs)
{
return Complex(r + rhs.r,i + rhs.i);
}
Complex operator-(const Complex &rhs)
{
return Complex(r - rhs.r,i - rhs.i);
}
Complex operator*(const Complex &rhs)
{
return Complex(r*rhs.r - i*rhs.i,i*rhs.r + r*rhs.i);
}
} pS[N], pH[N], pC[N], pD[N];
//len = 2^M,reverse F[i] with F[j] j为i二进制反转
void rader(Complex F[],int len)
{
int j = len >> 1;
for(int i = 1; i < len - 1; ++i)
{
if(i < j) swap(F[i],F[j]); // reverse
int k = len>>1;
while(j>=k)
{
j -= k;
k >>= 1;
}
if(j < k) j += k;
}
} void FFT(Complex F[],int len,int t)
{
rader(F,len);
for(int h=2; h<=len; h<<=1)
{
Complex wn(cos(-t*2*pi/h),sin(-t*2*pi/h));
for(int j=0; j<len; j+=h)
{
Complex E(1,0); //旋转因子
for(int k=j; k<j+h/2; ++k)
{
Complex u = F[k];
Complex v = E*F[k+h/2];
F[k] = u+v;
F[k+h/2] = u-v;
E=E*wn;
}
}
}
if(t==-1) //IDFT
for(int i=0; i<len; ++i)
F[i].r/=len;
} void Conv(Complex a[],Complex b[],int len) //求卷积
{
FFT(a,len,1);
FFT(b,len,1);
for(int i=0; i<len; ++i) a[i] = a[i]*b[i];
FFT(a,len,-1);
} long prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};
void init()
{
for(long i = 2 ; i < N ; i ++)
{
if(! isNotPrime[i])
prime[num_prime ++]=i;
for(long j = 0 ; j < num_prime && i * prime[j] < N ; j ++)
{
isNotPrime[i * prime[j]] = 1;
if( !(i % prime[j] ) )
break;
}
}
} int main()
{
int A, B, C;
init();
while(scanf("%d%d%d", &A, &B, &C) && (A+B+C))
{
memset(pS, 0, sizeof(pS));
memset(pH, 0, sizeof(pH));
memset(pC, 0, sizeof(pC));
memset(pD, 0, sizeof(pD));
for(int i=2; i<=B; ++i)
if(isNotPrime[i])
pS[i]=pH[i]=pC[i]=pD[i]=Complex(1);
int len=1;
while(len<B) len<<=1;
len<<=3;
while(C--)
{
int v;
char type;
scanf("%d%c", &v, &type);
switch(type)
{
case 'S':pS[v]=Complex(0);break;
case 'H':pH[v]=Complex(0);break;
case 'C':pC[v]=Complex(0);break;
case 'D':pD[v]=Complex(0);break;
}
}
FFT(pS, len, 1), FFT(pH, len, 1), FFT(pC, len, 1), FFT(pD, len, 1);
for(int i=0; i<len; ++i)
pS[i]=pS[i]*pH[i]*pC[i]*pD[i];
FFT(pS, len, -1);
for(int i=A; i<=B; ++i)
printf("%lld\n", (long long)(pS[i].r+0.5));
puts("");
}
return 0;
}
UVA 12298 Super Poker II (FFT)的更多相关文章
- UVA - 12298 Super Poker II (FFT+母函数)
题意:有四种花色的牌,每种花色的牌中只能使用数值的约数个数大于2的牌.现在遗失了c张牌.每种花色选一张,求值在区间[a,b]的每个数值的选择方法有多少. 分析:约数个数大于2,即合数.所以先预处理出5 ...
- UVA - 12298 Super Poker II NTT
UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数&q ...
- FFT(快速傅里叶变换):UVAoj 12298 - Super Poker II
题目:就是现在有一堆扑克里面的牌有无数张, 每种合数的牌有4中不同花色各一张(0, 1都不是合数), 没有质数或者大小是0或者1的牌现在这堆牌中缺失了其中的 c 张牌, 告诉你a, b, c接下来c张 ...
- Super Poker II UVA - 12298 FFT_生成函数
Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define double long do ...
- UVa12298 Super Poker II(母函数 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...
- bzoj2487: Super Poker II
Description I have a set of super poker cards, consisting of an infinite number of cards. For each p ...
- UVA12298 Super Poker II
怎么又是没人写题解的UVA好题,个人感觉应该是生成函数的大板子题了. 直接做肯定爆炸,考虑来一发优化,我们记一个多项式,其中\(i\)次项的系数就表示对于\(i\)这个数有多少种表示方式. 那么很明显 ...
- UVA 11426 - GCD - Extreme (II) (数论)
UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...
- UVA 10869 - Brownie Points II(树阵)
UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
随机推荐
- 使用wordpress搭建的一个微信小程序
- hystrix熔断器之配置
HystrixCommandProperties命令执行相关配置: hystrix.command.[commandkey].execution.isolation.strategy 隔离策略THRE ...
- Spring boot +Thymeleaf 搭建springweb
对接天猫精灵的时候需要有网关服务器方提供几个页面,服务器已经有了,spring boot的 纯后台的,就加了Thymeleaf jar包添加几个页面跳转 maven配置 <!-- 引入thy ...
- 关于JSON的零碎小知识
1.ali的fastjson在将实体类转成jsonString的时候,一些首字母大写的字段会自动修改为小字母,这种字段加 @JsonProperty(value = "DL_id" ...
- junit源码之Runner
Runner 定义了执行用例的执行器方法. public abstract class Runner implements Describable { /* 获取描述 */ public abstra ...
- python实现多分类评价指标
1.什么是多分类? 参考:https://www.jianshu.com/p/9332fcfbd197 针对多类问题的分类中,具体讲有两种,即multiclass classification和mul ...
- 原子类的 ABA 问题
原子引用 public class AtomicReferenceDemo { public static void main(String[] args) { User cuzz = new Use ...
- C# NX二次开发环境搭建
在网上看到一篇C#二次开发环境搭建的文章:NX二次开发-使用NXOPEN C#手工搭建开发环境配置 ,写得非常好.我按照文章操作,过程中遇到几个问题,把问题分享给大家,希望对各位有帮助. 注意三点: ...
- 文本编辑-vi
命令行模式: 底行模式:
- 12.深入k8s:kubelet创建pod流程源码分析
转载请声明出处哦~,本篇文章发布于luozhiyun的博客:https://www.luozhiyun.com 源码版本是1.19 在上一篇中,我们知道在kubelet中,工作核心就是围绕着整个syn ...