Codeforces Round #527 (Div. 3)C(多重集,STRING)
using namespace std;
const int maxn=1e6+7;
pair<string,int>p[maxn];
int nn,n;
int cmp(pair<string,int>a,pair<string,int>b){
return a.first.length()<b.first.length();
}
char ans[maxn];
multiset<string>sst;
int judge(string pre,string suf){
string s=pre+suf[suf.length()-1];//将最长的加上同样长的另一个字符可以拼接成完整串(或是完整串的镜像)
multiset<string>st;
for(int i=0;i<n-1;i++){
st.insert(s.substr(0,i+1));//0-i+1
st.insert(s.substr(i+1));//i+1-end
}//将所有前缀后缀全被扔进多重集st中
if(st!=sst)//镜像
return 0;
for(int i=1;i<=nn;i+=2){
string ss=s.substr(0,p[i].first.length());//截取长度开始比较,string的优势在于可以直接等于比较
string sss=s.substr(n-p[i].first.length());
if(p[i].first==ss && p[i+1].first==sss){
ans[p[i].second]='P';
ans[p[i+1].second]='S';
}
else{
ans[p[i+1].second]='P';
ans[p[i].second]='S';
}
}
return 1;
}
scanf("%d",&n);
nn=2*n-2;
for(int i=1;i<=nn;i++){
cin>>p[i].first;
p[i].second=i;
sst.insert(p[i].first);
}
sort(p+1,p+1+nn,cmp);
if(judge(p[nn].first,p[nn-1].first)){
for(int i=1;i<=nn;i++){
printf("%c",ans[i]);
}
}
else if(judge(p[nn-1].first,p[nn].first)){
for(int i=1;i<=nn;i++){
printf("%c",ans[i]);
}
}
return 0;
}
Codeforces Round #527 (Div. 3)C(多重集,STRING)的更多相关文章
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- Codeforces Round #303 (Div. 2) B. Equidistant String 水题
B. Equidistant String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #656 (Div. 3) D. a-Good String
题目链接:https://codeforces.com/contest/1385/problem/D 题意 一个小写字母串称为 $c-good\ string$,如果至少满足以下条件之一: 字符串长度 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes
题目链接 题意:给你一个长度n,还有2*n-2个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可. 思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是 ...
随机推荐
- JS正则表达式,记录自己所学所用的内容
还没接触正则表达式感觉确实有那么点难度,但接触到后自己琢磨了几天也没发现那么难. 现在教教刚学的或者还没接触正则表达式的同学们入入门,一起学习. 正则表达式基本语法 ***************** ...
- PHP限制IP访问 只允许指定IP访问 允许*号通配符过滤IP
/** * 检测访问的ip是否为规定的允许的ip * Enter description here ... */ function check_ip(){ $ALLOWED_IP=array('192 ...
- 20179203 《Linux内核原理与分析》第十周作业
第17章 设备与模块 一.设备类型 1. Linux及Unix系统: 块设备 字符设备 网络设备 2.块设备: 通常缩写为blkdev,它是可寻址的,寻址以块为单位,块大小随设备不同而不同:块设备通常 ...
- ACM学习历程—ZOJ 3777 Problem Arrangement(递推 && 状压)
Description The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem sett ...
- Apache+OpenSSL实现证书服务器提供HTTPS
通过 Linux+Apache+OpenSSL 实现 SSL ( Secure Socket Layer )证书服务器,提供安全的 HTTPS ( Hypertext Transfer Protoco ...
- POJ百练—IP地址转换
#include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; void ...
- 在浏览器中输入url并回车后发生了什么?
1 解析url url主要由以下几个部分组成: 1 传输协议 2 服务器 3 域名 4 端口 5 虚拟目录 6 文件名 7 锚 8 参数 2 DNS(域名)解析 找到域名对应的ip 3 浏览器与网站建 ...
- rails常用命令示例
数据迁移命令 1.一下命令执行后会在db\migrate下产生同名数据迁移文件(文件内容可自行修改,基本语法见“数据迁移文件”部分) 创建model:rails generate model user ...
- Android源码中添加APP
参考罗升阳<Android系统源代码情景分析> 在Android源码中,我们通常把实验性质的Android APP放在packages/experimental目录下.对于一个简单的应用程 ...
- Zeppelin的入门使用系列之创建新的Notebook(一)
不多说,直接上干货! 前期博客 hadoop-2.6.0.tar.gz + spark-1.6.1-bin-hadoop2.6.tgz + zeppelin-0.5.6-incubating-bin- ...