题目链接

题意:给你一个长度n,还有2*n-2个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可。

思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是长度为n-1的字符串一个是前缀一个是后缀,那么只要搜两次就完事了,一个当前缀不行就换另一个当前缀,然后中间判断一下即可。

ps:这也是给远古题,没补,因为最不喜欢 字符串的题,,,qwq。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
int n;
struct uzi
{
int i;
string a;
bool operator <(const uzi &t)const{
return a.size()>t.a.size();
}
}p[555];
char ans[555];
int dfs1(){
for(int i=3;i<=2*n-2;i+=2){
int bj=0;
if(p[1].a.find(p[i].a)==0){
string A=p[2].a,B=p[i+1].a;
reverse(A.begin(),A.end());
reverse(B.begin(),B.end());
if(A.find(B)==0){
ans[p[i].i]='P';
ans[p[i+1].i]='S';bj=1;}
}
if(p[1].a.find(p[i+1].a)==0){
string A=p[2].a,B=p[i].a;
reverse(A.begin(),A.end());
reverse(B.begin(),B.end());
if(A.find(B)==0){
ans[p[i].i]='S';
ans[p[i+1].i]='P';bj=1;}
}
if(!bj)return 0;
}
return 1;
}
int dfs2(){
for(int i=3;i<=2*n-2;i+=2){
int bj=0;
if(p[2].a.find(p[i].a)==0){
string A=p[1].a,B=p[i+1].a;
reverse(A.begin(),A.end());
reverse(B.begin(),B.end());
if(A.find(B)==0){
ans[p[i].i]='P';
ans[p[i+1].i]='S';bj=1;}
}
if(p[2].a.find(p[i+1].a)==0){
string A=p[1].a,B=p[i].a;
reverse(A.begin(),A.end());
reverse(B.begin(),B.end());
if(A.find(B)==0){
ans[p[i].i]='S';
ans[p[i+1].i]='P';bj=1;}
}
if(!bj)return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=2*n-2;i++){
cin>>p[i].a;
p[i].i=i;
}
sort(p+1,p+1+2*n-2);
if(dfs1()){
ans[p[1].i]='P';
ans[p[2].i]='S';
for(int i=1;i<=2*n-2;i++)cout<<ans[i];
return 0;
}
dfs2();
ans[p[2].i]='P';
ans[p[1].i]='S';
for(int i=1;i<=2*n-2;i++)cout<<ans[i];
return 0;
}

Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes的更多相关文章

  1. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes (思维,字符串)

    题意:给你某个字符串的\(n-1\)个前缀和\(n-1\)个后缀,保证每个所给的前缀后缀长度从\([1,n-1]\)都有,问你所给的子串是前缀还是后缀. 题解:这题最关键的是那两个长度为\(n-1\) ...

  2. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes

                                                        D. Prefixes and Suffixes You have a string s = s ...

  3. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)

    D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  5. Codeforces Round #527 (Div. 3)

    一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...

  6. Codeforces Round #587 (Div. 3) A. Prefixes

    链接: https://codeforces.com/contest/1216/problem/A 题意: Nikolay got a string s of even length n, which ...

  7. Codeforces Round #527 (Div. 3) F. Tree with Maximum Cost 【DFS换根 || 树形dp】

    传送门:http://codeforces.com/contest/1092/problem/F F. Tree with Maximum Cost time limit per test 2 sec ...

  8. Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...

  9. Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...

随机推荐

  1. scala的多种集合的使用(2)之集合常用方法

    一.常用的集合方法 1.可遍历集合的常用方法 下表列出了Traverable在所有集合常用的方法.接下来的符号: c代表一个集合 f代表一个函数 p代表一个谓词 n代表一个数字 op代表一个简单的操作 ...

  2. 【zabbix教程系列】五、邮件报警设置(脚本方式)

    本方式是使用外部邮箱账号发送报警邮件到指定邮箱. 好处是:此邮箱账号既能发送邮件,也能接收邮件,而且避免被当做垃圾邮件. 一.zabbix-server端安装mailx服务 [root@ltt01 ~ ...

  3. 【微信小程序】rpx尺寸单位的应用

    前言:微信小程序中的rpx尺寸单位用起来很方便.他是怎么实现计算的呢?(这里要注意的是,常规浏览器解析css代码的时候会把font-size小于12px的字体转成12px,不会让他小于12px的,而微 ...

  4. 微信小程序之模板的使用

    初步学习小程序模板,就把过程写一下了. 1.在app.json里面注册temlate/public,生成模板wxml,wxss等系列页面 2.注册模板 <1>无数据传参的模板 <te ...

  5. .Net Core学习地址

    官方教程:https://docs.microsoft.com/zh-cn/aspnet/core/ 入门无忧网:http://www.rm5u.com/netcore/netcore-intro.h ...

  6. ORACLE数据闪回

    ALTER TABLE SPM_CON_PAYMENT_RECEIPT ENABLE ROW MOVEMENT;   -- 表名 FLASHBACK TABLE SPM_CON_PAYMENT_REC ...

  7. kafka的安装以及基本用法

    kafka的安装 kafka依赖于ZooKeeper,所以在运行kafka之前需要先部署ZooKeeper集群,ZooKeeper集群部署方式分为两种,一种是单独部署(推荐),另外一种是使用kafka ...

  8. Python 库/模块的安装、查看

    关于如何查看本地python类库详细信息的方法 关于如何查看本地python类库详细信息的方法 - 小白裸奔 - CSDN博客 python -m pydoc -p 1234 help('module ...

  9. 改善python程序的建议[转]

    <编写高质量代码 改善Python程序的91个建议> <编写高质量代码 改善Python程序的91个建议>读后程序学习小结 - BigDeng_2014的专栏 - CSDN博客 ...

  10. 浏览器开发者工具console

    浏览器开发者工具基本使用教程 谷歌Chrome浏览器开发者工具教程-基础功能篇 - 算命de博客 - CSDN博客 JavaScript Console 对象 | 菜鸟教程