[2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 ]Rock Paper Scissors Lizard Spock.(FFT)

Description:

Didi is a curious baby. One day, she finds a curious game, which named Rock Paper Scissors Lizard Spock.

The game is an upgraded version of the game named Rock, Paper, Scissors. Each player chooses an option . And then those players show their choices that was previously hidden at the same time. If the winner defeats the others, she gets a point.

The rules are as follows. 

Scissors cuts Paper

Paper covers Rock

Rock crushes Lizard

Lizard poisons Spock

Spock smashes Scissors

Scissors decapitates Lizard

Lizard eats Paper

Paper disproves Spock

Spock vaporizes Rock

(and as it always has) Rock crushes Scissors.

242dd42a2834349b5866a238c9ea15ce36d3be2f.jpg

(this pic is from baike.baidu.com)

But Didi is a little silly, she always loses the game. In order to keep her calm, her friend Tangtang writes down the order on a list and show it to her. Didi also writes down her order on another list, like p1.png.

(Rock-R Paper-P Scissors-S Lizard-L Spock-K)

However, Didi may skip some her friends' choices to find the position to get the most winning points of the game, like p2.png

Can you help Didi find the max points she can get?

Input:

The first line contains the list of choices of Didi's friend, the second line contains the list of choices of Didi.

(1<=len(s2)<=len(s1)<=1e6)

Output:

One line contains an integer indicating the maximum number of wining point.

输出时每行末尾的多余空格,不影响答案正确性

样例输入

RRRRRRRRRLLL
RRRS

样例输出

3








发现这题就是个套路水题
字符集很小,枚举计算每个字符对每个开始位置作出的贡献就行了
就很套路 qaq







 
 1 #include"bits/stdc++.h"
 2 #define sd(x) scanf("%lf",&(x));
 3 #define sld(x) scanf("%lld",&(x));
 4 using namespace std;
 5 
 6 const int maxn = 2e6+10;
 7 const double Pi = acos(-1.0);
 8 
 9 struct cp
10 {
11     double x,y;
12     cp (double xx=0,double yy=0)
13     {x=xx,y=yy;}
14 }a[maxn],b[maxn];
15 cp operator + (cp a,cp b){ return cp(a.x+b.x , a.y+b.y);}
16 cp operator - (cp a,cp b){ return cp(a.x-b.x , a.y-b.y);}
17 cp operator * (cp a,cp b){ return cp(a.x*b.x-a.y*b.y , a.x*b.y+a.y*b.x);}//不懂的看复数的运算那部分
18 
19 int n,m;
20 int l,r[maxn];
21 int limit = 1;
22 
23 
24 inline void fft(cp *a,int ff)
25 {
26     for(int i=0;i<limit;i++)
27     if(i<r[i])swap(a[i],a[r[i]]);
28     for(int mid=1;mid<limit;mid<<=1)
29         {
30         cp wn(cos(Pi/mid) , ff*sin(Pi/mid));
31         for(int R=mid<<1,j=0;j<limit;j+=R)
32         {
33             cp w(1,0);
34             for(int k=0;k<mid;k++,w=w*wn)
35             {
36                 cp x=a[j+k],y=w*a[j+mid+k];
37                 a[j+k]=x+y;
38                 a[j+mid+k]=x-y;
39             }
40         }
41 
42     }
43 
44 
45 }
46 char s[2000000];
47 char t[2000000];
48 int ans[2000000];
49 
50 int main()
51 {
52 
53    cin>>s>>t;
54    n=strlen(s); m=strlen(t);
55    reverse(t,t+m);
56   // cout<<t<<endl;
57    string mm="SPRLKSPRLK";
58     while(limit<=n+m)limit<<=1,l++;
59    for(int i=0;i<limit;i++)
60    r[i]=(r[i>>1]>>1)|( (i&1)<<(l-1));
61 
62    for(int i=0;i<5;i++)
63    {
64        // cout<<mm[i]<<endl;
65         for(int j=0;j<limit;j++)a[j].x=a[j].y=b[j].x=b[j].y=0;
66         for(int j=0;j<m;j++)a[j].x=(t[j]==mm[i]);
67         for(int j=0;j<n;j++)b[j].x=(s[j]==mm[i+1] || s[j]==mm[i+3]);
68         //for(int j=0;j<m;j++)cout<<a[j].x<<" ";puts("");
69       //  for(int j=0;j<n;j++)cout<<b[j].x<<" ";puts("");
70         fft(a,1); fft(b,1);
71         for(int j=0;j<limit;j++)a[j]=a[j]*b[j];
72         fft(a,-1);
73         for(int j=m-1;j<n;j++)
74         ans[j] += int(a[j].x/limit + 0.5);
75      //   for(int j=m-1;j<n;j++)cout<<ans[j]<<" "; puts("");
76 
77    }
78    int mx=0;
79    for(int j=m-1;j<n;j++)mx=max(mx,ans[j]);
80    cout<<mx;
81 
82 
83 
84 
85 
86 
87 
88 }





















猜你喜欢

转载自www.cnblogs.com/zhangbuang/p/11074076.html