Bzoj2487:super Poker II

Source: Internet
Author: User

Description

I have a set of the Super Poker cards, consisting of an infinite number of cards. For each positive composite integer p, there
Was exactly four cards whose value is P:spade (S), Heart (H), Club (C) and Diamond (D). There is no cards of other values.
By ' composite integer ', we mean integers that has 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 with has 2 divisors:1 and 7. Note that 1 was not composite
(It has only 1 divisor).

Given a positive integer n, how many ways can-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, the card values sum to n? For example, if n=24, one-is
4S+6H+4C+10D, shown below:

Unfortunately, some of the cards is lost, but this makes the problem more interesting. To further make the problem even
More interesting (and challenging!), I'll give you II other positive integers a and B, and your need to find out all the
Answers for N=a, n=a+1, ..., n=b.

Input

The input contains at most 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. Lost cards is the same. The input is terminated by a=b=c=0. There
'll is at the 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 the test case, print b-a+1 integers Since the numbers might is large, you should output each
Integer modulo 1,000,000. Print a blank line after each test case.

Sample Input12 20 2
4S 6H
0 0 0Sample Output0
0
0
0
0
0
1
0
3HINT

Very simple FFT, read the surface can be.

Code

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 #defineMAXN 1310757 #definePi 3.141592653589793238468 #defineMoD 10000009 using namespacestd;TentypedefLong LongInt64; One Charch; A intL,R,M,N,X,LEN,TOT,RE[MAXN],PRIME[MAXN]; - BOOLOK,BO[MAXN]; - voidReadint&x) { the      for(ok=0, Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') ok=1; -      for(x=0; isdigit (ch); x=x*Ten+ch-'0', ch=GetChar ()); -     if(OK) x=-x; - } + intRev (intv) { -     intt=0; +      for(intI=0; i<len;i++) t<<=1,t|=v&1, v>>=1; A     returnT;  at } - structcomp{ -     DoubleRea,ima; -     voidClear () {rea=ima=0;} -Compoperator+(ConstComp &x) {return(comp) {rea+x.rea,ima+X.ima};} -Compoperator-(ConstComp &x) {return(comp) {rea-x.rea,ima-X.ima};} inCompoperator*(ConstComp &x) {return(comp) {rea*x.rea-ima*x.ima,rea*x.ima+ima*X.rea};} -}a[maxn],b[maxn],c[maxn],d[maxn],wn[2][maxn],wn,w,t1,t2; to voidFFT (Comp *a,intop) { +      for(intI=0, T=re[i];i<n;i++,t=re[i])if(i<t) swap (a[i],a[t]); -      for(ints=2; s<=n;s<<=1){ theWn=wn[op][s];//cout<<wn.rea<< ' <<wn.ima<<endl; *          for(intI=0; i<n;i+=s) { $w= (comp) {1,0};Panax Notoginseng              for(intj=i;j<i+ (s>>1); j++,w=w*WN) { -t1=a[j],t2=w*a[j+ (s>>1)]; thea[j]=t1+t2,a[j+ (s>>1)]=t1-T2; +             } A         } the     } +     if(OP) for(intI=0; i<n;i++) a[i].rea/=n,a[i].ima/=N; - } $ voidWork () { $      for(intI=0; i<=r;i++) a[i].rea= (Int64) round (A[i].rea)%mod,a[i].ima=0; -      for(inti=r+1; i<n;i++) a[i].clear (); - } the voidinit () { -      for(intI=2; i<maxn;i<<=1) wn[0][i]= (comp) {cos (2*pi/i), Sin (2*pi/i)};Wuyi      for(intI=2; i<maxn;i<<=1) wn[1][i]= (comp) {cos (-2*pi/i), Sin (-2*pi/i)}; the      for(intI=2; i<=50000; i++){ -         if(!bo[i]) prime[++tot]=i; Wu          for(intj=1; j<=tot&&i*prime[j]<=50000; j + +){ -bo[i*prime[j]]=1; About             if(! (I%prime[j])) Break; $         } -     }     - } - intMain () { A      for(init (), read (L), read (R), read (m);l&&R;read (L), read (R), read (m)) { +          for(len=0, n=1;n< ((r+1) <<1); len++,n<<=1); the          for(intI=0; i<n;i++) re[i]=rev (i); -          for(intI=0; i<n;i++) A[i].clear (), B[i].clear (), C[i].clear (), D[i].clear (); $          for(intI=2; i<r;i++) a[i].rea=b[i].rea=c[i].rea=d[i].rea=Bo[i]; the          for(intI=1; i<=m;i++){ the read (x); the             if(ch=='S') a[x].rea=0; the             Else if(ch=='H') b[x].rea=0; -             Else if(ch=='C') c[x].rea=0; in             Else if(ch=='D') d[x].rea=0; the         } theFFT (A,0), FFT (b,0), FFT (C,0), FFT (D,0); About          for(intI=0; i<n;i++) a[i]=a[i]*B[i]; theFFT (A,1), work (), FFT (A,0); the          for(intI=0; i<n;i++) a[i]=a[i]*C[i]; theFFT (A,1), work (), FFT (A,0); +          for(intI=0; i<n;i++) a[i]=a[i]*D[i]; -FFT (A,1), work (); the          for(inti=l;i<=r;i++) printf ("%d\n",(int) a[i].rea);BayiPuts""); the     } the     return 0; -}

Bzoj2487:super Poker II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.