当前位置:网站首页>第十九届浙江省 I. Barbecue
第十九届浙江省 I. Barbecue
2022-07-03 04:37:00 【Snow_raw】
第十九届浙江省 I. Barbecue
题意: 两个同学Putata和Budada在玩一个游戏,一开始给定一个固定长度的字符串,接下去有 m m m次询问,每次询问给定一个范围 [ l , r ] [l,r] [l,r],即从原字符串中截取 [ l , r ] [l,r] [l,r]的部分。从第一个同学Putata开始操作,每次操作必须从字串开头或末尾移除一个字符,如果操作前后字串变成回文串那么操作的同学判负,问每次询问哪个同学会赢?
Tip:
- 如果一开始第一个同学拿到的就是回文串,那么必定输掉比赛。
- 否则第一个同学拿到的就是非回文串,由于如果操作后子串变成回文串那么也算操作的同学输,那么在操作的同学最好的方案就是 非回文 * \implies *非回文
- 这就说明如果游戏没结束即上一次操作的同学结束操作后字串变成 非回文,那么意味着游戏如果始终持续进行除去 第一次操作 ,操作的同学拿到的 始终是非回文串 。那么通过不断操作,最终拿到长度为 2 2 2 的同学 必败 ,因为无论怎么操作,剩下的 1 1 1 个字符必定是 回文 。
- 那么显然有如果第一次操作的同学拿到的是 非回文 并且长度为偶数那么第一次操作的同学必败。如果是 非回文 并且长度为奇数,那么第一次操作的同学必胜。 当然非回文偶数字串有一种特殊情况为 a b a b a b a b abababab abababab,不管拿掉首个字符还是末尾字符都是操作者输,所以同样归类至第一种情况。
- 接下去就是如果判定区间 [ l , r ] [l,r] [l,r]内的字串为回文串,由于题目给到的查询有 1 0 6 10^6 106,所以支持的复杂度即为 O ( 1 ) O(1) O(1)查询。那么我们可以通过字符串 h a s h hash hash和 M a n a c h a r Manachar Manachar算法来进行处理。此处给出字符串 h a s h hash hash做法(学习地址)。
代码:
#include<bits/stdc++.h>
using namespace std;
int n,q;
const int P = 131;
const int N = 1e6+10;
unsigned long long p[N],t[N],t1[N];
unsigned long long query1(int l,int r){
return t[r]-t[l-1]*p[r-l+1];
}
unsigned long long query2(int l,int r){
return t1[l]-t1[r+1]*p[r-l+1];
}
char s[N];
int main(){
scanf("%d%d",&n,&q);
scanf("%s",s+1);
p[0]=1;
t[0]=0;
t1[n+1]=0;
for(int i=1;i<=n;i++){
p[i]=p[i-1]*P;
t[i]=t[i-1]*P+s[i];
}
for(int i=n;i>=1;i--){
t1[i]=t1[i+1]*P+s[i];
}
while(q--){
int l,r;
scanf("%d%d",&l,&r);
if(query1(l,r)==query2(l,r)){
printf("Budada\n");
}
else{
if((r-l+1)%2==0)printf("Budada\n");
else printf("Putata\n");
}
}
return 0;
}
边栏推荐
- Auman Galaxy new year of the tiger appreciation meeting was held in Beijing - won the double certification of "intelligent safety" and "efficient performance" of China Automotive Research Institute
- Symbol of array element product of leetcode simple problem
- 【工具跑SQL盲注】
- Web - Information Collection
- Learning practice: comprehensive application of cycle and branch structure (I)
- 2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
- Introduction to JVM principle
- Priv-app permission异常
- Kingbasees plug-in KDB of Jincang database_ date_ function
- Basic use of continuous integration server Jenkins
猜你喜欢

Introduction of pointer variables in function parameters

7. Integrated learning

Network security textual research recommendation

SSM based campus part-time platform for College Students

使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found

Redis persistence principle

arthas watch 抓取入参的某个字段/属性

2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
![[free completion] development of course guidance platform (source code +lunwen)](/img/14/7c1c822bda050a805fa7fc25b802a4.jpg)
[free completion] development of course guidance platform (source code +lunwen)

Learning practice: comprehensive application of cycle and branch structure (I)
随机推荐
Arthas watch grabs a field / attribute of the input parameter
When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully
【XSS绕过-防护策略】理解防护策略,更好的绕过
Triangular rasterization
Factor stock selection scoring model
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
Two drawing interfaces - 1 Matlab style interface
Bugku CTF daily question baby_ flag. txt
BMZCTF simple_ pop
X-ray normal based contour rendering
Ffmpeg tanscoding transcoding
[dynamic programming] subsequence problem
Dive into deep learning - 2.1 data operation & Exercise
【SQL注入】联合查询(最简单的注入方法)
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
IPhone x forgot the boot password
2022 P cylinder filling test content and P cylinder filling simulation test questions
Games101 Lesson 9 shading 3 Notes
[set theory] binary relationship (special relationship type | empty relationship | identity relationship | global relationship | divisive relationship | size relationship)