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] 题目描述 在处理阶乘时也需要借助计算器 ...
随机推荐
- httpclient httpcore jar包及源码
HttpClient HttpCore HttpComponents jar src download httpclient home help
- 页面引用jquery中文变乱码的问题
<script type="text/javascript" src="Js/JavaScript.js"></script> 方法 ...
- 1027 Colors in Mars (20 分)
1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...
- [UE4]GameMode
GameMode定义了正在玩的游戏规则,积分等方面,游戏中有些数据和逻辑不适合放在某一个对象身上,这些数据在整个游戏运行中腰持续存在的(比如:积分.排名). 每次游戏一启动,GameMode就被创建, ...
- php multicast多播实现详解
什么是多播? 网络中存在3中传播形式,单播,广播,多播. 1. 单播 : 就是1->1 2. 广播 : 1->多(广播域内) 3. 多播 : 1->组(一组ip) 1 2 3 4 5 ...
- golang web框架 beego 学习 (三) beego获取参数
直接上常用的例子吧: A: 获取URL中的参数 router func init() { beego.Router("/task/?:id/?:name", &co ...
- 目前学习的爬取小数据图片zzz
import os import threading import re import time from lxml import etree all_img_urls = [] # 图片列表页面的数 ...
- linux操作系统1 Linux入门
知识内容: 1.操作系统简介 2.Linux操作系统简介 3.Linux安装 4.Linux各大发行版本介绍 一.操作系统介绍 1.为什么需要操作系统 现代的计算机系统由处理器,主存,硬盘,键盘,鼠标 ...
- JPA注解@SecondaryTables 实现一个实体映射多张数据库表
参考:http://jingpin.jikexueyuan.com/article/46978.html Annotation Type SecondaryTables(参考:https://docs ...
- MAC CURL : Error:35 SSL certificate problem: Couldn't understand the server certificate format
起因,使用极光推送最新的版本,里面curl使用https请求,而导致证书出错.一看就懵逼了,从来没遇到过这样的问题,二话不说直接百度,然后就更加懵逼了,搜出来的没有中文内容,对于我这种英文渣来说,简直 ...