ACM-ICPC2018北京网络赛 Tomb Raider(暴力)
题目2 : Tomb Raider
描述
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#include<bits/stdc++.h>
#define MAX 15
using namespace std;
typedef long long ll; string s[MAX];
int n;
string ss,ans; int find(string x){
int lenx=x.length();
for(int i=;i<n;i++){
int len=s[i].length();
int f=;
for(int k=;k<len;k++){
if(s[i][k]==x[]){
int c=;int l=-;
for(int j=k;j<len;j++){
if(s[i][j]==x[c]){
if(l==-) l=j;
c++;
if(c>=lenx&&(j-l+)<=(len/)){
f=;
break;
}
}
}
if(f==) break;
}
}
if(f==) return ;
}
return ;
}
void dfs(int en,string x,int st){
if(st>=en){
if(find(x)==){
if(x.length()>ans.length()){
ans=x;
}
else if(x.length()==ans.length()){
if(x<ans){
ans=x;
}
}
}
return;
}
for(int i=;i<=;i++){
if(i==) dfs(en,x+ss[st],st+);
else dfs(en,x,st+);
}
}
int main()
{
int t,i,j;
while(~scanf("%d",&n)){
for(i=;i<n;i++){
cin>>s[i];
s[i]+=s[i];
}
ans="{";
int len=s[].length();
for(i=;i<len;i++){
int minn=min(len-i,len/);
for(j=;j<=minn;j++){
ss=s[].substr(i,j);
dfs(j,"",);
}
}
if(ans=="{") printf("0\n");
else cout<<ans<<endl;
}
return ;
}
ACM-ICPC2018北京网络赛 Tomb Raider(暴力)的更多相关文章
- acm 2015北京网络赛 F Couple Trees 树链剖分+主席树
Couple Trees Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/123 ...
- acm 2015北京网络赛 F Couple Trees 主席树+树链剖分
提交 题意:给了两棵树,他们的跟都是1,然后询问,u,v 表 示在第一棵树上在u点往根节点走 , 第二棵树在v点往根节点走,然后求他们能到达的最早的那个共同的点 解: 我们将第一棵树进行书链剖,然后第 ...
- hihocoder1236(北京网络赛J):scores 分块+bitset
北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...
- 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT
2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...
- 2015北京网络赛 J Scores bitset+分块
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- HDU-4041-Eliminate Witches! (11年北京网络赛!!)
Eliminate Witches! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Tomb Raider(暴力模拟)
Tomb Raider https://hihocoder.com/problemset/problem/1829?sid=1394836 时间限制:1000ms 单点时限:1000ms 内存限制:2 ...
- hihoCoder-1829 2018亚洲区预选赛北京赛站网络赛 B.Tomb Raider 暴力 字符串
题面 题意:给你n个串,每个串都可以选择它的一个长度为n的环形子串(比如abcdf的就有abcdf,bcdfa,cdfab,dfabc,fabcd),求这个n个串的这些子串的最长公共子序列(每个串按顺 ...
随机推荐
- ubuntu 安装 pygame 很好玩的东西
1. 简介 pygame 是基于对 SDL库的python 封装,提供python接口.SDL(Simple DirectMedia Layer) 是一个跨平台的游戏开发库,方便游戏开发和移植.目前最 ...
- power law 幂定律
y=cx∧a 卖品销量排名与销量
- Xshell 连接centOS虚拟机、centOS内置python版本升级
Xshell 连接虚拟机 前置条件:VMware Workstation 12.5.1.Xshell 5 . centOS 6.6 1.打开虚拟机,输入用户名和密码: 2.输出命令:ifconfig ...
- 用JavaScript判断一个对象是否数组?
Q:如何判断一个对象是否为数组? A1:判断对象的constructor是否指向Array, 接着判断对应的特殊属性,如length,splice之类.这个很容易冒充. A2:使用instanceof ...
- Android tab页制作
全屏启动页 activity_launcher <?xml version="1.0" encoding="utf-8"?> <Relativ ...
- ListView多选和单选模式重新整理
超简单的单选和多选ListView 在开发过程中,我们经常会使用ListView去呈现列表数据,比如商品列表,通话记录,联系人列表等等,在一些情况下,我们还需要去选择其中的一些列表数据进行编辑.以前, ...
- mySql执行效率分析
1.关于SQL查询效率,100w数据,查询只要1秒,与您分享: 机器情况p4: 2.4内存: 1 Gos: windows 2003数据库: ms sql server 2000目的: 查询性能测试, ...
- 微信公众号验证TOKEN
服务端验证微信token header('Content-type:text'); define("TOKEN", "weixin"); $signature ...
- 9.2 NOIP提高组试题精解(2)
9-18 fruit.c #include <stdio.h> #define MAXN 10000 int Queue1[MAXN], Queue2[MAXN]; void Insert ...
- window/body/img/iframe 的onload事件
在html页面中,只有body,img,iframe这一类标签具有onload事件. onload事件表示在当前元素载入完成后发生的事件.其中,window也有onload事件,但是跟body的是同一 ...