Tomb Raider(暴力模拟)
Tomb Raider
https://hihocoder.com/problemset/problem/1829?sid=1394836
描述
Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her limits when she discovers the island where her father disappeared. In this mysterious island, Lara finds a tomb with a very heavy door. To open the door, Lara must input the password at the stone keyboard on the door. But what is the password? After reading the research notes written in her father's notebook, Lara finds out that the key is on the statue beside the door.
The statue is wearing many arm rings on which some letters are carved. So there is a string on each ring. Because the letters are carved on a circle and the spaces between any adjacent letters are all equal, any letter can be the starting letter of the string. The longest common subsequence (let's call it "LCS") of the strings on all rings is the password. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
For example, there are two strings on two arm rings: s1 = "abcdefg" and s2 = "zaxcdkgb". Then "acdg" is a LCS if you consider 'a' as the starting letter of s1, and consider 'z' or 'a' as the starting letter of s2. But if you consider 'd' as the starting letter of s1 and s2, you can get "dgac" as a LCS. If there are more than one LCS, the password is the one which is the smallest in lexicographical order.
Please find the password for Lara.
输入
There are no more than 10 test cases.
In each case:
The first line is an integer n, meaning there are n (0 < n ≤ 10) arm rings.
Then n lines follow. Each line is a string on an arm ring consisting of only lowercase letters. The length of the string is no more than 8.
输出
For each case, print the password. If there is no LCS, print 0 instead.
- 样例输入
-
2
abcdefg
zaxcdkgb
5
abcdef
kedajceu
adbac
abcdef
abcdafc
2
abc
def - 样例输出
-
acdg
acd
0 求所有字符串的公共的LCS,因为数据范围很小,所以可以把第一个字符串的所有子序列求出来,和剩余的一个一个比较
注意,n是大于0的,所以有可能只有一个字符串。因为被看清这点,多调了半小时。。。#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdio>
using namespace std; string s[];
string ans[];
int main(){ int n;
string str;
while(cin>>n){
for(int i=;i<=n;i++){
cin>>s[i];
}
int coun=;
int len=s[].length();
int num=<<len;
for(int i=;i<num;i++){
int j=i;
str="";
for(int k=;k<len;k++){
if((j>>k)&){
str+=s[][k];
}
}
int co=;
for(int k=;k<=n;k++){
for(int h=;h<s[k].length();h++){
int len1=str.length();
int len2=s[k].length();
int l1=,l2=;
while(l1<len1&&l2<len2){
if(str[l1]==s[k][l2]){
l1++;
l2++;
}
else{
l2++;
}
}
if(l1==len1){
co++;
break;
}
char hh=s[k][];
s[k]=s[k].substr();
s[k]+=hh;
}
if(co==n){
ans[coun++]=str;
}
}
}
int prelen=;
if(coun==){
cout<<<<endl;
}
else{
for(int i=;i<coun;i++){
if(prelen<ans[i].length()){
prelen=ans[i].length();
}
}
string aa; for(int i=;i<coun;i++){
if(prelen==ans[i].length()){
aa=ans[i];
break;
}
}
string pre="zzzzzzzzzzzz";
for(int i=;i<aa.length();i++){
char tmp=aa[];
aa=aa.substr();
aa+=tmp;
if(pre>aa){
pre=aa;
}
}
cout<<pre<<endl;
} } }
Tomb Raider(暴力模拟)的更多相关文章
- hihoCoder-1829 2018亚洲区预选赛北京赛站网络赛 B.Tomb Raider 暴力 字符串
题面 题意:给你n个串,每个串都可以选择它的一个长度为n的环形子串(比如abcdf的就有abcdf,bcdfa,cdfab,dfabc,fabcd),求这个n个串的这些子串的最长公共子序列(每个串按顺 ...
- ACM-ICPC2018北京网络赛 Tomb Raider(暴力)
题目2 : Tomb Raider 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, the fiercely independent daughte ...
- ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 B Tomb Raider 【二进制枚举】
任意门:http://hihocoder.com/problemset/problem/1829 Tomb Raider 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 L ...
- bnuoj 20832 Calculating Yuan Fen(暴力模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...
- POJ 1013 小水题 暴力模拟
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11 ...
- hdu_1006 Tick and Tick(暴力模拟)
hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...
- hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B
P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...
- 美团2018年CodeM大赛-资格赛 分数 暴力模拟
链接:https://www.nowcoder.com/acm/contest/138/D来源:牛客网 小胖参加了人生中最重要的比赛——MedoC资格赛.MedoC的资格赛由m轮构成,使用常见的“加权 ...
- 2018/7/31-zznu-oj-问题 B: N! 普拉斯 -【求大数的阶乘-ll存不下-然后取尾零的个数输出-暴力模拟】
问题 B: N! 普拉斯 时间限制: 1 Sec 内存限制: 128 MB提交: 114 解决: 35[提交] [状态] [讨论版] [命题人:admin] 题目描述 在处理阶乘时也需要借助计算器 ...
随机推荐
- binlog之五:mysqlbinlog解析binlog乱码问题解密
发现MySQL库的binlog日志出来都是乱码,如下所示: BINLOG ’ IXZqVhNIAAAALQAAAGcBAAAAAHoAAAAAAAEABHRlc3QAAno0AAEDAABUOcnY ...
- HUD 1175 连连看
连连看 Time Limit : 20000/10000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
- 杂项:GitHub
ylbtech-杂项:GitHub gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. gitHub于2008年4月10日正式上线, ...
- 学习笔记之Cloud computing
Cloud computing - Wikipedia https://en.wikipedia.org/wiki/Cloud_computing
- 学习笔记之Unit testing/Integration testing/dotnet test and xUnit
source code https://github.com/haotang923/dotnet/tree/master/src Unit testing C# code in .NET Core u ...
- post 中文数据到elasticsearch restful接口报json_parse_exception 问题
我们的客户端程序直接调用es 的restful接口, 通过post json数据去查询, 但post数据有中文的时候,有些中文会报异常,有些中文不会 {"error":{" ...
- HTML5中对于网络是否断开的检测.很有意思哦
//事件的封装 var EventUtil = { addHandler: function (element, type, handler) {//注册事件 if (element.addEvent ...
- 省市县_me
# question 11import astfrom functools import reduce def file_read(): with open('D:\\pytharm\\ji ...
- js 解决图片居中问题
下述方法能够解决图片居中问题: (1)宽一些或者高一些(相对父元素的大小):图片在父元素的可视范围内显示图片的中间位置 (2)小一些(相对父元素的大小):图片在父元素的可视范围内居中显示 实现原理:根 ...
- git 隐藏文件删除
1.首先切换到当前目录 cd /Users/wlm/Desktop/XXX/XXX 2.执行下面的命令: defaults write com.apple.finder AppleShowAllFil ...