题目链接

题意:给你一个长度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. 【alpha阶段】第九次Scrum Meeting

    每日任务内容 队员 昨日完成任务 明日要完成的任务 牛宇航 #26 评价总览接口编写https://github.com/rRetr0Git/rateMyCourse/issues/26 #26 评价 ...

  2. 云计算openstack共享组件(2)——Memcache 缓存系统

    一.缓存系统 在大型海量并发访问网站及openstack等集群中,对于关系型数据库,尤其是大型关系型数据库,如果对其进行每秒上万次的并发访问,并且每次访问都在一个有上亿条记录的数据表中查询某条记录时, ...

  3. 使用C++进行WMI查询的简单封装

    封装WMI查询的简单类CWMIUtil 头文件WMIUtil.h #pragma once #include <Wbemidl.h> class CWMIUtil { public: CW ...

  4. mysql查看死锁和解除锁

    解除正在死锁的状态有两种方法: 第一种: 1.查询是否锁表 show OPEN TABLES where In_use > 0; 2.查询进程(如果您有SUPER权限,您可以看到所有线程.否则, ...

  5. 内置函数(sorted、map、enumerate、filter、reduce)

    1.sorted() 语法: sorted(iterable, cmp=None, key=None, reverse=False) 把iterable中的items进行排序之后,返回一个新的列表,原 ...

  6. Codeforces Round #543

    (比赛链接)[http://codeforces.com/contest/1120] A 给出一个长度为m的序列a 可以删除一些数 使得最后从没删的第一个数开始 每k个一截 截出的n个多重集合中 至少 ...

  7. shell-计算虚拟机创建时间

    因为要验证虚拟机创建时间,所以写了下面一个脚本 #!/bin/bash ################################################################ ...

  8. [unix]commvault在unix系统上本地安装报“NFS directory cannot be used”

    远程安装持续的pending: 本地安装报“NFS directory cannot be used” 修改安装包 安装目录 的权限, 从777改回775. 就可以解决这个报错.

  9. jmeter笔记(6)--参数化--函数助手

    函数助手提供的功能很多,本次笔记主要整理_CSVRead 函数._Random函数以及_RandomString函数的基础使用方法 1._CSVRead 作用:直接读取csv文件的值生成函数 1.在[ ...

  10. kms访问数据库的方式(该篇只是作为个人笔记,不具有任何公共参考意图)

    项目类型:winform 语言:C# 服务程序:webservice(webservice我本人也不了解,在下一章中会总结一下对它的概念的简单理解) 情景描述:简单创建一个窗体,实现学生信息(姓名.性 ...