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. SRM 600(1-250pt,500pt)

    DIV1 250pt 题意:给定一个vector<int>A,若能从里面选出一些数,使得他们按位或的值为x,则称x为吉利数.给定k,问最少要从A里面去掉多少个数,才能使k变为不吉利数. 解 ...

  2. apt局域网源搭建

    1, 准备Packages.gz

  3. Blue Jeans - POJ 3080(多串的共同子串)

    题目大意:有M个串,每个串的长度都是60,查找这M个串的最长公共子串(连续的),长度不能小于3,如果同等长度的有多个输出字典序最小的那个.   分析:因为串不多,而且比较短,所致直接暴力枚举的第一个串 ...

  4. linux —— ubuntu 初次安装问题

    本文收集了我自己安装ubuntu系统时的一些想法和遇到的一些问题,以及一些我自己感兴趣的软件的安装方法等 1. 50G ubuntu 分区方案 <plan> <key> / & ...

  5. 双系统如何正确的使用修复BCD工具分享

    安装双系统时候,用于种种原因会导致开机启动只显示一个系统,此时需要修复下BCD即可. 下面介绍下两个修复BCD工具软件: 1.easybcd(双系统引导修复工具) v2.2.0.182 汉化版 下载地 ...

  6. javascript中错误使用var造成undefined

    在javascript中依据变量作用的范围不同分为局部变量和全局变量,直接定义的变量是全局变量,全局变量能够被全部的脚本訪问:在函数中定义的变量是局部变量,局部变量仅仅在函数内有效. 假设全局变量和局 ...

  7. android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

    shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看  api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...

  8. Android 模仿QQ空间风格的 UI(转)

    本文内容 环境 演示模仿QQ空间风格的UI 虽然这个 UI 跟现在的QQ空间有点差别,但是也能学到很多东西. 下载 Demo 环境 Windows 7 64 位 Eclipse ADT V22.6.2 ...

  9. Java基础知识强化之IO流笔记20:FileOutputStream写出数据实现换行和追加写入

    1.  如何实现数据的换行? (1) package com.himi.fileoutputstream; import java.io.FileNotFoundException; import j ...

  10. hash练习

    /* poj 1200 Crazy Search 字符串hash O(n)枚举起点 然后O(1)查询子串hash值 然后O(n)找不一样的个数 复杂度是线性的 */ #include<iostr ...