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 ...
随机推荐
- php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...
- Linux一键安装PHP/JAVA环境OneinStack
OneinStack 是一款PHP/JAVA环境一键配置工具. OneinStack包含以下组合 lnmp(Linux + Nginx+ MySQL ...
- Manacher思想 SCOI2013 密码
关于$\mathrm{Manacher}$算法,网上介绍已经很全面 这里说一下自己的理解 这里的$rad$数组:$rad_i$表示以以位置i为中心的最长回文串的回文半径(不包括i这个点). 朴素的思想 ...
- Linq to sql并发与事务
本文转载:http://www.cnblogs.com/lovecherry/archive/2007/08/20/862365.html 检测并发 首先使用下面的SQL语句查询数据库的产品表: se ...
- 解决java.sql.SQLException: Parameter number X is not an OUT parameter--转
最近独自一个人写项目,孤军奋战的程序猿可真伤不起! Java 调用MYSQL带输入输出参数存储过程时如题错误:java.sql.SQLException: Parameter number X is ...
- ios中框架介绍
ios中框架介绍 参考博客: 参考文章:框架介绍 框架介绍 框架就是一个目录,一个目录包含了共享库,访问共享库里面的代码的头文件,和其他的图片和声音的资源文件.一个共享库定义的方法和函数可以被应用程序 ...
- Javascript 控制style 小结
style.top 如: c.style.top=scrollTop; 在IE各版本中可以,Safari, chrome, Firefox都不work, 需要在后面 + "px";
- 使用EF 的简单的增删改查
using DAL; using Model; using System; using System.Collections.Generic; using System.Linq; using Sys ...
- C# DateTime.Now
//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...
- linux 'more' command.
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...