当前位置:网站首页>Codeforces 1629 D. pecuriar movie preferences - simple thinking, palindrome strings
Codeforces 1629 D. pecuriar movie preferences - simple thinking, palindrome strings
2022-06-12 13:32:00 【Tianyi City*】
The question :
Here you are. n A string , Each string is no longer than 3, You can select a subsequence so that the string constructed by the subsequence is a palindrome string .
Answer key :
You can know that if a string itself is a palindrome string , Then it can be constructed .
There are two remaining cases :
1. The length is 2 when , Suppose the string is ab.
① Find out if there is a length of 2 And the string is ba.
② Find out that the back length is 3 The last two characters of are ba.
2. The length is 3 when , Suppose the string is abc:
① Find out that the back length is 2 And the string is ba
② Find out that the back length is 3 And the string is cba.
You can see that the length is zero 2 and 3 The difference in time is the second , So we can use hash to do this problem .
map[0] The length stored is 2 String
map[1] The length stored is 3 String
The length is 3 There are two cases when querying the string of , So we make the length 3 In the case of a string, insert both cases into map[1] Inside .
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
map<int,int>mp[2];
char ss[N][5];
int main()
{
char s[5];
int t;
scanf("%d",&t);
while(t--){
int n,f=0;
scanf("%d",&n);
mp[0].clear(),mp[1].clear();
for(int i=1;i<=n;i++)scanf("%s",ss[i]);
for(int i=n;i;i--){
strcpy(s,ss[i]);
if(f)break;
int has=0,len=strlen(s);
if(len==1)f=1;
else if(len==2){
if(s[0]==s[1])f=1;
has=(int)s[0]*1000+(int)s[1];
if(mp[0][has]||mp[1][has])f=1;
has=(int)s[1]*1000+(int)s[0];
mp[0][has]=1;
}
else{
if(s[0]==s[2])f=1;
has=(int)s[0]*1000+(int)s[1];
if(mp[0][has])f=1;
has=has*1000+(int)s[2];
if(mp[1][has])f=1;
has=((int)s[2]*1000+(int)s[1])*1000+(int)s[0];
mp[1][has]=1;
has=(int)s[2]*1000+(int)s[1];
mp[1][has]=1;
}
}
printf("%s\n",f?"YES":"NO");
}
return 0;
}
边栏推荐
- 看完这一篇就够了,web中文开发
- Further understanding of the network
- Getting started with NVIDIA Jetson nano Developer Kit
- import torch_geometric 第一个图网络例子
- RK3399平台开发系列讲解(内核调试篇)2.50、systrace的使用
- 微信web开发者工具使用教程,web开发问题
- 2062: [example 1.3] movie tickets
- There was an error installing mysql. Follow the link below to CMD
- 【刷题篇】抽牌获胜的概率
- Implementing tensorflow deep learning framework similarflow with numpy
猜你喜欢

C#DBHelper_ FactoryDB_ GetConn

Resume NFT platform trustrecruit joined Octopus network as a candidate application chain

Online picture material
![[embedded] serial communication and its case](/img/5c/2e691e5ef03c7d65fd514e8b940e7b.jpg)
[embedded] serial communication and its case

成功跳槽阿里,进阶学习

Further understanding of the network

Chrome debugging tool

Automatic Generation of Visual-Textual Presentation Layout

torch_geometric mini batch 的那些事
![[Title brushing] Super washing machine](/img/f9/0c69afafa8b32afc5df5e91d6af172.png)
[Title brushing] Super washing machine
随机推荐
go-zero 微服务实战系列(二、服务拆分)
[cloud native | kubernetes] kubernetes networkpolicy
VGA display color bar and picture (FPGA)
Seeking magic square of order n with C language
成功定级腾讯T3-2,万字解析
FFmpeg 学习指南
list和dict的应用
【刷题篇】超级洗衣机
Wechat web developer tools tutorial, web development issues
Implementing pytorch style deep learning framework similartorch with numpy
imagemagick:a gentle introduction to magick++
1414: [17noip popularization group] score
Application of bit operation in C language
Successfully rated Tencent t3-2, 10000 word parsing
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S
Chrome debugging tool
Does jupyternotebook have a Chinese character database. Can you recognize handwritten Chinese in deep learning
Innovation training (x) advanced interface beautification
[cloud native | kubernetes] learn more about ingress
Tinyxml Usage Summary