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

12 20 2
4S 6H
0 0 0

Sample Output

0
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的更多相关文章

  1. UVA - 12298 Super Poker II NTT

    UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数&q ...

  2. UVa12298 Super Poker II(母函数 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...

  3. Super Poker II UVA - 12298 FFT_生成函数

    Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define double long do ...

  4. FFT(快速傅里叶变换):UVAoj 12298 - Super Poker II

    题目:就是现在有一堆扑克里面的牌有无数张, 每种合数的牌有4中不同花色各一张(0, 1都不是合数), 没有质数或者大小是0或者1的牌现在这堆牌中缺失了其中的 c 张牌, 告诉你a, b, c接下来c张 ...

  5. UVA12298 Super Poker II

    怎么又是没人写题解的UVA好题,个人感觉应该是生成函数的大板子题了. 直接做肯定爆炸,考虑来一发优化,我们记一个多项式,其中\(i\)次项的系数就表示对于\(i\)这个数有多少种表示方式. 那么很明显 ...

  6. UVA - 12298 Super Poker II (FFT+母函数)

    题意:有四种花色的牌,每种花色的牌中只能使用数值的约数个数大于2的牌.现在遗失了c张牌.每种花色选一张,求值在区间[a,b]的每个数值的选择方法有多少. 分析:约数个数大于2,即合数.所以先预处理出5 ...

  7. UVA 12298 Super Poker II (FFT)

    #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using ...

  8. 浅谈FFT(快速傅里叶变换)

    本文主要简单写写自己在算法竞赛中学习FFT的经历以及一些自己的理解和想法. FFT的介绍以及入门就不赘述了,网上有许多相关的资料,入门的话推荐这篇博客:FFT(最详细最通俗的入门手册),里面介绍得很详 ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. [Locked] Binary Tree Longest Consecutive Sequence

    Binary Tree Longest Consecutive Sequence Given a binary tree, find the length of the longest consecu ...

  2. AOJ 0525 穷举

    题意:有一个烤饼器可以烤r行c列的煎饼,煎饼可以正面朝上(用1表示)也可以背面朝上(用0表示).一次可将同一行或同一列的煎饼全部翻转.现在需要把尽可能多的煎饼翻成正面朝上,问最多能使多少煎饼正面朝上? ...

  3. [转]windows10 64位环境下安装mysql5.7.17

    今天以zip模式在windows10 64位环境下安装mysql5.7,到最后一步提示mysql服务无法启动. 安装步骤如下: 1.配置环境变量 我的电脑->属性->高级->环境变量 ...

  4. redis linux 基本命令

    找到一个哥们 写的都是一步步打基础的学习东西 不光是知识也是学习方式 都值得学习.. reids 传送们-->> http://xuelianbobo.iteye.com/category ...

  5. Android Developers:两个视图渐变

    淡入淡出动画(也被称为渐隐)逐渐淡出一个UI组件,同时淡入另一个.这个动画在你想在你的应用程序中切换内容或者是视图的情况下非常有用.淡入淡出非常微妙并短,但支持从一个屏幕到下一个屏幕流畅的过渡.当你不 ...

  6. MongoDB 逻辑与操作

    看下面两个例子 rs1:PRIMARY> db.display.find({$and: [{$where: '(1386813645 - this.last_active_time > 3 ...

  7. SAP-MM:创建采购组织、采购组

    创建采购组织 路径:SPRO – IMG – 企业结构 – 定义 – 物料管理 – 维护采购组织   操作: Step 1.点击"新条目". Step 2.维护"采购组织 ...

  8. HDU1700:Points on Cycle

    Problem Description There is a cycle with its center on the origin. Now give you a point on the cycl ...

  9. 给想上MIT的牛学生说几句

    [来信] 老师您好! 非常冒昧的来打搅您,仅仅是在学习上实在有些困惑才来向您求教一番. 我是计算机科学与技术的大一学生,我非常喜欢我自己的专业,可是学校里讲的东西太慢,太浅,所以我一般都是自学,我在自 ...

  10. cocos2d-x 背景音乐播放

    Code // on "init" you need to initialize your instance bool HelloWorld::init() {      bool ...