题目链接

题意:给你一个长度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. CentOS 安装 ceph 单机版(luminous版本)

    一.环境准备 CentOS Linux release 7.4.1708 (Core)一台,4块磁盘(sda.sdb,.sdc.sdd) 192.168.27.130 nceph 二.配置环境 1.修 ...

  2. Django入门之路

    Web框架开发-Django基础之web应用,Http协议 web框架开发-web框架简介,wsgiref模块,DIY一个web框架 web框架开发-Django简介 web框架开发-静态文件配置 w ...

  3. kvm虚拟化介绍

    一.虚拟化分类 1.虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机.在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立的空间内运行而互相 ...

  4. 身份认证功能chiro的使用

    package com.cun;import org.apache.shiro.SecurityUtils;import org.apache.shiro.authc.*;import org.apa ...

  5. php将字符串转为二进制数据串

    /** * 将字符串转换成二进制 * @param type $str * @return type */ function StrToBin($str){ //1.列出每个字符 $arr = pre ...

  6. mybatis中常见的问题总结

    如下所有举例基于springboot+mybatis项目中,SSH使用mybatis的写法也一样,只是形式不同而已 问题1.org.apache.ibatis.binding.BindingExcep ...

  7. python面对对象(不全解)

    面对对象:以人类为例,人类通用功能:吃喝拉撒,就可以封装成一个类,不同功能:嫖赌毒,就是对象的不同功能.继承,多态… 上码 class Person(object): def __init__(sel ...

  8. MySQL函数--(1)

    /*函数与存储过程的区别1.存储过程:可以有0个返回值,可以有多个返回值函数:有且仅有一个返回值*/ #创建语法create FUNCTION 函数名(参数列表) return 返回类型BEGIN函数 ...

  9. Python scrapy爬虫数据保存到MySQL数据库

    除将爬取到的信息写入文件中之外,程序也可通过修改 Pipeline 文件将数据保存到数据库中.为了使用数据库来保存爬取到的信息,在 MySQL 的 python 数据库中执行如下 SQL 语句来创建 ...

  10. flutter 主题切换

    ### 主题 ``` // 1.main主文件 import 'package:flutter_smart_park/config/theme.dart' show AppTheme; Provide ...