Rock Paper Scissors+fft

问题 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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值