题目链接

题意:给你一个长度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. .net问号的作用

    ??运算符(C# 参考)http://msdn.microsoft.com/zh-cn/library/ms173224.aspx 可以为 null 的类型(C# 编程指南)http://msdn.m ...

  2. centos6.5搭建hadoop完整教程

    https://blog.csdn.net/hanzl1/article/details/79040380 博客地址http://blog.csdn.net/pucao_cug/article/det ...

  3. 关于ES6的module的循环加载

    今天写js时,碰到了一个模块循环加载的错误,下面时例子: // testa.mjs import testb from './testb.mjs'; const {b} = testb; const ...

  4. 小A的柱状图

    链接 [https://ac.nowcoder.com/acm/contest/549/H] 题意 [] 分析 很显然你必须找到该高度下往左右找到第一个高度比该位置小的.这个区间的宽*该高度.就当前能 ...

  5. C#中的PropertyGrid绑定对象,通过改变某一值而动态设置部分属性的特性

    问题:如下,我定义了一个对象,默认设置属性WindowSize ,WindowSize 为不可见,通过改变SaveOnClose的值,动态的改变不可见的属性的显示和隐藏. [DefaultProper ...

  6. JS 获取某个容器控件中id包含制定字符串的控件id列表

    //获取某容器控件中id包含某字符串的控件id列表 //参数:容器控件.要查找的控件的id关键字 function GetIdListBySubKey(container,subIdKey) { va ...

  7. Maven版本不一致的时候,使用指定版本进行编译

    最近用Maven打包项目(本地jdk11)后放到服务器(jdk8)后,报[java.lang.UnsupportedClassVersionError]版本不一致错误. 网上资料说是修改Intelli ...

  8. 利用ajax技术 实现用户注册。

    一.ajax? 异步加载技术,在不刷新网页的前提下,实现部分网页内容的更新! AJAX 最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容. 思考? 注册界面刚好可以应用 ...

  9. Analysis Services features supported by SQL Server editions

    Analysis Services (servers) Feature Enterprise Standard Web Express with Advanced Services Express w ...

  10. python一(字符串,字典)

    list操作 name = ['小王','小米','小张','王强','张三','李四'] name.append('黄霑')#添加元素在最后一个 name.insert(,'王五')#指定下标插入元 ...