Rock Paper Scissors+fft

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ujn20161222/article/details/82938692

问题 H: Rock Paper Scissors

时间限制: 1 Sec  内存限制: 128 MB
提交: 36  解决: 5
[提交] [状态] [讨论版] [命题人:admin]

https://vjudge.net/problem/UVALive-6118

https://blog.csdn.net/infinity_edge/article/details/79079348

题解:枚举你出的每一种拳,将其设为 1, 其他的设为 0 ,将电脑序列中你能赢的拳设为 1, 其他的设为 0

,则对于每一个pos,只比较你的该种出拳能够胜利的局数为


然后把你的序列反过来,就变成了卷积的形式:


做三遍 FFT 即可。

题目描述

There is a Rock Paper Scissors (RPS) machine which generates Rock, Paper, or Scissors randomly. You also have a similar small Rock Paper Scissors machine. Before the game, the RPS machine will generate a list of its choice of Rock, Paper, or Scissors of the length n and your machine also will generates a list of its choice of the length m. That is, you know the whole list of the RPS’s choices and you have the list of your machine’s choices. Of course, each choice of the machines is one of the three options (Rock, Paper, or Scissors).

Now, you start playing Rock Paper Scissors game. In every match, you compare the list of RPS’s choice and the list of your machine’s in sequence and decide whose machine would win. However, only you may skip some RPS’s choices to find the position to get the most winning points of your machine. After you decide to start match you cannot skip the match till the end of the match. ‘R’ stands for Rock, ‘P’ stands for Paper, and ‘S’ stands for Scissors.

For example, suppose that the RPS’s list is “RSPPSSSRRPPR” and your machine’s list is “RRRR”. To get the most winning points, you should start the match after skipping three RPS’s choices or four RPS’s choices. (See Figure H.1.) Then, you can win in three matches. The draw case is not considered.

Figure H.1. The most winning position against RPS machine when n = 12 and m = 4.


Given the list of RPS’s choices and the list of your choices, find the position to get the maximum number of wining matches.

输入

Your program is to read from standard input. The first line contains two positive integers n and m (1 ≤ m < n ≤ 100,000), where n is the length of the string for RPS machine and m is the length of the string for your machine. Following the first line contains the list of choices of RPS machine and the second line contains the list of choices of your machine.

输出

Your program is to write to standard output. The first line should contain an integer indicating the maximum number of wining matches

样例输入

12 4
RSPPSSSRRPPR
RRRR

样例输出

3
scanf("%d %d",&n,&m);
	scanf("%s %s",s,t);
	
	reverse(t,t+m);
	int len=(1<<18);
	initRev(len,18);
	for(int i=0;i<3;i++){
		for(int i=0;i<len;i++)
			A[i].x=A[i].y=B[i].x=B[i].y=0;
		for(int j=0;j<n;j++)
			if(s[j]==h[i+1])A[j].x+=1;
		for(int j=0;j<m;j++)
			if(t[j]==h[i])B[j].x+=1;
		FFT(A,len,1),FFT(B,len,1);
		for(int j=0;j<len;j++)
		A[j]=A[j]*B[j];
		FFT(A,len,-1);
		for(int j=0;j<len;j++)
		c[j]+=round(A[j].x);
	}
	int ans=0;
	for(int i=m-1;i<len;i++)
	ans=max(ans,c[i]);
	printf("%d\n",ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ujn20161222/article/details/82938692