2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227

题目链接:https://nanti.jisuanke.com/t/26219

Rock Paper Scissors Lizard Spock

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.

(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

.

(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

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.

忽略每行输出的末尾多余空格

样例输入1

RRRRRRRRRLLL
RRRS

样例输出1

3

样例输入2

RSSPKKLLRKPS
RSRS

样例输出2

2
ACM-ICPC Asia Training League   宁夏理工学院

题解:

因为之前做过codeforces 528D. Fuzzy Search  ,感觉就不难了,你要是不会这题可以先去做cf528d,有个详细的题解:https://blog.csdn.net/u013368721/article/details/45565729

【FFT求字符串匹配的问题一般都是将模式串反转,然后将其与主串进行卷积运算】

枚举五种出拳方式,每种都做fft,最后扫一遍最大值即可求出最佳匹配出的赢的最大次数。(具体fft原理不懂orz,我就是套着原来板子写的...)

#include<bits/stdc++.h>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = <<;
const double PI = acos(-1.0);
int n, m;
struct Complex {
double x,y;
Complex(double _x = 0.0,double _y = 0.0){
x = _x; y = _y;
}
Complex operator -(const Complex &b)const{
return Complex(x-b.x,y-b.y);
}
Complex operator +(const Complex &b)const{
return Complex(x+b.x,y+b.y);
}
Complex operator *(const Complex &b)const{
return Complex(x*b.x-y*b.y,x*b.y+y*b.x);
}
Complex operator * (const double &b)const{
return Complex(x * b,y * b);
}
Complex operator / (const double &b)const{
return Complex(x / b,y / b);
}
};
void change(Complex y[], int len) {
int i, j, k;
for(i = , j = len/;i <len-;i++) {
if(i < j)swap(y[i],y[j]);
k = len/;
while(j >= k) {
j -= k;
k /= ;
}
if(j < k) j += k;
}
}
void fft(Complex y[],int len,int on) {
change(y,len);
for(int h = ; h <= len; h <<= ) {
Complex wn(cos(-on**PI/h),sin(-on**PI/h));
for(int j = ;j < len;j+=h) {
Complex w(,);
for(int k = j;k < j+h/;k++) {
Complex u = y[k];
Complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
if(on == -)
for(int i = ;i < len;i++)
y[i].x /= len;
}
Complex a[N], b[N], c[N];
char s[N], t[N];
int sum[N];
int main() {
int i, j, ans = , ma, nn;
scanf("%s %s", s, t);
n = strlen(s);
m = strlen(t);
reverse(t, t+m);
ma = max(n, m); nn = ;
while(nn < * ma) nn<<=;
CLR(c, ); CLR(sum, );
//R vs L S
CLR(a, ); CLR(b, );
for(i = ; i < n; ++i) a[i].x = (s[i]=='L'||s[i]=='S');
for(i = ; i < m; ++i) b[i].x = (t[i]=='R');
fft(a, nn, ); fft(b, nn, );
for(i = ; i < nn ;++i) c[i] = a[i] * b[i];
fft(c, nn, -);
for(i = m-; i < n; ++i)
sum[i] += (int)(c[i].x+0.5);
//P vs R K
CLR(a, ); CLR(b, );
for(i = ; i < n; ++i) a[i].x = (s[i]=='R'||s[i]=='K');
for(i = ; i < m; ++i) b[i].x = (t[i]=='P');
fft(a, nn, ); fft(b, nn, );
for(i = ; i < nn ;++i) c[i] = a[i] * b[i];
fft(c, nn, -);
for(i = m-; i < n; ++i)
sum[i] += (int)(c[i].x+0.5);
//S vs P L
CLR(a, ); CLR(b, );
for(i = ; i < n; ++i) a[i].x = (s[i]=='P'||s[i]=='L');
for(i = ; i < m; ++i) b[i].x = (t[i]=='S');
fft(a, nn, ); fft(b, nn, );
for(i = ; i < nn ;++i) c[i] = a[i] * b[i];
fft(c, nn, -);
for(i = m-; i < n; ++i)
sum[i] += (int)(c[i].x+0.5);
//L vs P K
CLR(a, ); CLR(b, );
for(i = ; i < n; ++i) a[i].x = (s[i]=='P'||s[i]=='K');
for(i = ; i < m; ++i) b[i].x = (t[i]=='L');
fft(a, nn, ); fft(b, nn, );
for(i = ; i < nn ;++i) c[i] = a[i] * b[i];
fft(c, nn, -);
for(i = m-; i < n; ++i)
sum[i] += (int)(c[i].x+0.5);
//K vs R S
CLR(a, ); CLR(b, );
for(i = ; i < n; ++i) a[i].x = (s[i]=='R'||s[i]=='S');
for(i = ; i < m; ++i) b[i].x = (t[i]=='K');
fft(a, nn, ); fft(b, nn, );
for(i = ; i < nn ;++i) c[i] = a[i] * b[i];
fft(c, nn, -);
for(i = m-; i < n; ++i)
sum[i] += (int)(c[i].x+0.5);
for(i = m-; i < n; ++i) ans = max(ans, sum[i]);
printf("%d\n", ans);
return ;
}

2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)的更多相关文章

  1. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 F题 Clever King(最小割)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  2. 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)

    若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...

  3. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 I. Reversion Count (java大数)

    Description: There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1 ...

  4. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 D Merchandise (斜率优化)

    Description: The elderly aunts always like to look for bargains and preferential merchandise. Now th ...

  5. 2017年中国大学生程序设计竞赛-中南地区赛暨第八届湘潭市大学生计算机程序设计大赛题解&源码(A.高斯消元,D,模拟,E,前缀和,F,LCS,H,Prim算法,I,胡搞,J,树状数组)

    A------------------------------------------------------------------------------------ 题目链接:http://20 ...

  6. 第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(沈阳)

    有时候,很简单的模板题,可能有人没有做出来,(特指 I ),到时候一定要把所有的题目全部看一遍 目录 B 题解 E F 题解 H I 题解&代码 J B 输入样例 3 2 1 2 1 2 3 ...

  7. 2018中国大学生程序设计竞赛 - 网络选拔赛 1001 - Buy and Resell 【优先队列维护最小堆+贪心】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6438 Buy and Resell Time Limit: 2000/1000 MS (Java/O ...

  8. 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...

  9. 2018中国大学生程序设计竞赛 - 网络选拔赛 1009 - Tree and Permutation 【dfs+树上两点距离和】

    Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. 设计模式学习--面向对象的5条设计原则之依赖倒置原则--DIP

    一.DIP简介(DIP--Dependency Inversion Principle): 1.高层模块不应该依赖于低层模块,二者都应该依赖于抽象.2.抽象不应该依赖于细节,细节应该依赖于抽象.   ...

  2. 宜立方商城中,mvn报错'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-webmvc:jar报错

    'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:s ...

  3. Spring中的Bean的配置形式

    Spring中Bean的配置形式有两种,基于XML文件的方式和基于注解的方式. 1.基于XML文件的方式配置Bean <?xml version="1.0" encoding ...

  4. hdu 2181 水搜索

    哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. PHP生成缩略图(1)--简单缩略图

    原理:就是将大图缩小并另存为小图 以此图为例,使其生成缩略图! 首先要使用到以下函数 imagecopyresampled() 重采样拷贝部分图像并调整大小 bool imagecopyresampl ...

  6. MySql基本学习知识点:

    1.Mysql的简介: (1):常识: MySQL是一种关系数据库管理系统,是一种开源软件 由瑞典MySQL AB公司开发,2008年1月16号被Sun公司收购.2009年,SUN又被Oracle收购 ...

  7. Ubuntu14.04安装Torch7笔记

    Ubuntu14.04安装Torch7笔记 利用快捷键Ctrl+Alt+T打开Ubuntu终端 第一步: 获取安装LuauJIT(C语言编写的Lua的解释器)和Torch所必需的依赖包. 代码如下: ...

  8. js和jquery中获取非行间样式

    样式又分为了行间样式和非行间样式.一般来说行间样式用的是比较少的,因为它能够作用的范围就只有一个元素,而非行间样式的作用范围可以是一类元素(即拥有相同德标签,或者说是有相同的类名,(当然id名不可能相 ...

  9. Jquery插件网站持续添加。。。

    Look Fro Less,Do More www.jq22.com

  10. Java集合 -- ArrayList集合及应用

    JAVA集合 对象数组 集合类之ArrayList 学生管理系统 斗地主案例 NO.one 对象数组 1.1 对象数组描述 A:基本类型的数组:存储的元素为基本类型 int[] arr={1,2,3, ...