bzoj2487: Super Poker II
Description
I have a set of super poker cards, consisting of an infinite number of cards. For each positive composite integer p, there
are exactly four cards whose value is p: Spade(S), Heart(H), Club(C) and
Diamond(D). There are no cards of other values.
By “composite integer”, we
mean integers that have more than 2 divisors. For example, 6 is a composite
integer, since it
has 4 divisors: 1, 2, 3, 6; 7 is not a composite number,
since 7 only has 2 divisors: 1 and 7. Note that 1 is not composite
(it has
only 1 divisor).
Given a positive integer n, how many ways can you pick
up exactly one card from each suit (i.e. exactly one spade card,
one heart
card, one club card and one diamond card), so that the card values sum to n? For
example, if n=24, one way is
4S+6H+4C+10D, shown below:
Unfortunately, some of the cards are lost,
but this makes the problem more interesting. To further make the problem even
more interesting (and challenging!), I’ll give you two other positive
integers a and b, and you need to find out all the
answers for n=a, n=a+1,
…, n=b.
Input
The input contains at most 25 test cases.
Each test case begins with 3 integers a, b and c, where c is the number of lost
cards. The next line contains c strings, representing the lost cards. Each
card is formatted as valueS, valueH, valueC or
valueD, where value is a
composite integer. No two lost cards are the same. The input is terminated by
a=b=c=0. There
will be at most one test case where a=1, b=50,000 and
c<=10,000. For other test cases, 1<=a<=b<=100,
0<=c<=10.
Output
For each test case, print b-a+1 integers, one
in each line. Since the numbers might be large, you should output each
integer modulo 1,000,000. Print a blank line after each test
case.
Sample Input
4S 6H
0 0 0
Sample Output
0
0
0
0
0
1
0
3
HINT
很简单的fft,看懂题面即可。
code:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 131075
#define pi 3.14159265358979323846
#define mod 1000000
using namespace std;
typedef long long int64;
char ch;
int l,r,m,n,x,len,tot,re[maxn],prime[maxn];
bool ok,bo[maxn];
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
int rev(int v){
int t=;
for (int i=;i<len;i++) t<<=,t|=v&,v>>=;
return t;
}
struct comp{
double rea,ima;
void clear(){rea=ima=;}
comp operator +(const comp &x){return (comp){rea+x.rea,ima+x.ima};}
comp operator -(const comp &x){return (comp){rea-x.rea,ima-x.ima};}
comp operator *(const comp &x){return (comp){rea*x.rea-ima*x.ima,rea*x.ima+ima*x.rea};}
}a[maxn],b[maxn],c[maxn],d[maxn],Wn[][maxn],wn,w,t1,t2;
void fft(comp *a,int op){
for (int i=,t=re[i];i<n;i++,t=re[i]) if (i<t) swap(a[i],a[t]);
for (int s=;s<=n;s<<=){
wn=Wn[op][s];//cout<<wn.rea<<' '<<wn.ima<<endl;
for (int i=;i<n;i+=s){
w=(comp){,};
for (int j=i;j<i+(s>>);j++,w=w*wn){
t1=a[j],t2=w*a[j+(s>>)];
a[j]=t1+t2,a[j+(s>>)]=t1-t2;
}
}
}
if (op) for (int i=;i<n;i++) a[i].rea/=n,a[i].ima/=n;
}
void work(){
for (int i=;i<=r;i++) a[i].rea=(int64)round(a[i].rea)%mod,a[i].ima=;
for (int i=r+;i<n;i++) a[i].clear();
}
void init(){
for (int i=;i<maxn;i<<=) Wn[][i]=(comp){cos(*pi/i),sin(*pi/i)};
for (int i=;i<maxn;i<<=) Wn[][i]=(comp){cos(-*pi/i),sin(-*pi/i)};
for (int i=;i<=;i++){
if (!bo[i]) prime[++tot]=i;
for (int j=;j<=tot&&i*prime[j]<=;j++){
bo[i*prime[j]]=;
if (!(i%prime[j])) break;
}
}
}
int main(){
for (init(),read(l),read(r),read(m);l&&r;read(l),read(r),read(m)){
for (len=,n=;n<((r+)<<);len++,n<<=);
for (int i=;i<n;i++) re[i]=rev(i);
for (int i=;i<n;i++) a[i].clear(),b[i].clear(),c[i].clear(),d[i].clear();
for (int i=;i<r;i++) a[i].rea=b[i].rea=c[i].rea=d[i].rea=bo[i];
for (int i=;i<=m;i++){
read(x);
if (ch=='S') a[x].rea=;
else if (ch=='H') b[x].rea=;
else if (ch=='C') c[x].rea=;
else if (ch=='D') d[x].rea=;
}
fft(a,),fft(b,),fft(c,),fft(d,);
for (int i=;i<n;i++) a[i]=a[i]*b[i];
fft(a,),work(),fft(a,);
for (int i=;i<n;i++) a[i]=a[i]*c[i];
fft(a,),work(),fft(a,);
for (int i=;i<n;i++) a[i]=a[i]*d[i];
fft(a,),work();
for (int i=l;i<=r;i++) printf("%d\n",(int)a[i].rea);
puts("");
}
return ;
}
bzoj2487: Super Poker II的更多相关文章
- UVA - 12298 Super Poker II NTT
UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数&q ...
- UVa12298 Super Poker II(母函数 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...
- Super Poker II UVA - 12298 FFT_生成函数
Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define double long do ...
- FFT(快速傅里叶变换):UVAoj 12298 - Super Poker II
题目:就是现在有一堆扑克里面的牌有无数张, 每种合数的牌有4中不同花色各一张(0, 1都不是合数), 没有质数或者大小是0或者1的牌现在这堆牌中缺失了其中的 c 张牌, 告诉你a, b, c接下来c张 ...
- UVA12298 Super Poker II
怎么又是没人写题解的UVA好题,个人感觉应该是生成函数的大板子题了. 直接做肯定爆炸,考虑来一发优化,我们记一个多项式,其中\(i\)次项的系数就表示对于\(i\)这个数有多少种表示方式. 那么很明显 ...
- UVA - 12298 Super Poker II (FFT+母函数)
题意:有四种花色的牌,每种花色的牌中只能使用数值的约数个数大于2的牌.现在遗失了c张牌.每种花色选一张,求值在区间[a,b]的每个数值的选择方法有多少. 分析:约数个数大于2,即合数.所以先预处理出5 ...
- UVA 12298 Super Poker II (FFT)
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using ...
- 浅谈FFT(快速傅里叶变换)
本文主要简单写写自己在算法竞赛中学习FFT的经历以及一些自己的理解和想法. FFT的介绍以及入门就不赘述了,网上有许多相关的资料,入门的话推荐这篇博客:FFT(最详细最通俗的入门手册),里面介绍得很详 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- 九度online judge 1543 二叉树
题目1543:无限完全二叉树的层次遍历 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:389 解决:54 题目描述: 有一棵无限完全二叉树,他的根节点是1/1,且任意一个节点p/q的左儿 ...
- Directx 3D编程实例:随机绘制的立体图案旋转
最近朋友建议我写一些关于微软云技术的博客留给学校下一届的学生们看,怕下一届的MSTC断档.于是我也觉的有这个必要. 写了几篇博客之后,我觉得也有必要把这一年的学习内容放在博客做个纪念,就这样写了本篇博 ...
- JS 操作 HTML 自定义属性
<input type="text" id="txtBox" displayName="123456" /> 获取自定义属性值: ...
- Haskell 差点儿无痛苦上手指南
趁着自己重装Linux 虚拟机的机会,把安装 haskell 的过程记录一下,顺便帮那些还犹豫徘徊在haskell门外的读者入门. 基本概念: Haskell : 是一门通用函数式语言,差点儿能够进行 ...
- [Javascript] Writing conventional commits with commitizen
Because semantic-release requires a specific message format, it's easier to follow this convention u ...
- TCP/IP协议族-----10、搬家IP
- android 窗体透明的,黑暗度等的设置技巧
设置透明度(这是窗体本身的透明度,非背景) 1 WindowManager.LayoutParams lp=getWindow().getAttributes(); 2 lp.alpha=0.3f; ...
- PHP安全编程:留心后门URL 直接可以通过URL访问(转)
后门URL是指虽然无需直接调用的资源能直接通过URL访问.例如,下面WEB应用可能向登入用户显示敏感信息: <?php $authenticated = FALSE; $authenticate ...
- Understanding Extension Class Loading--官方
http://docs.spring.io/spring-amqp/docs/1.3.6.RELEASE/reference/html/sample-apps.html#d4e1285 http:// ...
- 第二篇:R语言数据可视化之数据塑形技术
前言 绘制统计图形时,半数以上的时间会花在调用绘图命令之前的数据塑型操作上.因为在把数据送进绘图函数前,还得将数据框转换为适当格式才行. 本文将给出使用R语言进行数据塑型的一些基本的技巧,更多技术细节 ...