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个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可. 思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是 ...
随机推荐
- 1.angular js 学习网址
双向数据绑定: http://html-js.com/article/1863
- 分享知识-快乐自己:SSH 整合 Demo
楼主A: XML 版 SSH整合Demo https://github.com/MlqBeginner/BlogGardenWarehouse/blob/master/SSH%E6%95%B4%E5% ...
- 一致性问题和Raft一致性算法——一致性问题是无法彻底解决的,可以说一个分布式系统可靠性达到99.99…%,但不能说它达到了100%
一致性问题 一致性算法是用来解决一致性问题的,那么什么是一致性问题呢? 在分布式系统中,一致性问题(consensus problem)是指对于一组服务器,给定一组操作,我们需要一个协议使得最后它们的 ...
- (转)通过汇编语言实现C协程
转自:http://www.cnblogs.com/sniperHW/archive/2012/06/19/2554574.html 协程的概念就不介绍了,不清楚的同学可以自己google,windo ...
- JAVA堆内存和栈内存初步了解
一.堆内存和栈内存 程序运行时内存分配有三种:静态存储分配,栈式存储分配,堆式存储分配 1.静态存储分配: 在程序编译时就可以确定数据目标在运行时所需要的内存,因此在编译时就为其分配固定大小的内存. ...
- 根据sid或sqlID查询SQL
根据sid查询已经执行过的sql select sql_text from v$sqlarea a,v$session b where a.SQL_ID=b.PREV_SQL_ID and b.SID ...
- 标准模板库(STL)学习指南之set集合
set是关联容器.其键值就是实值,实值就是键值,不可以有重复,所以我们不能通过set的迭代器来改变set的元素的值,set拥有和list相同的特性:当对他进行插入和删除操作的时候,操作之前的迭代器依然 ...
- bzoj 2093 [Poi2010]Frog——滑动窗口
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2093 找第k近的可以用一个含k个元素的滑动窗口来实现. 卡空间也还行,但卡时间.不要预处理倍 ...
- 洛谷 P4546 & bzoj 5020 在美妙的数学王国中畅游 —— LCT+泰勒展开
题目:https://www.luogu.org/problemnew/show/P4546 先写了个55分的部分分,直接用LCT维护即可,在洛谷上拿了60分: 注意各处 pushup,而且 spla ...
- keepalive安装和配置
1.下载安装包并解压 sudo wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz tar zxvf keepalived ...