Tomb Raider

https://hihocoder.com/problemset/problem/1829?sid=1394836

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

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的,所以有可能只有一个字符串。因为被看清这点,多调了半小时。。。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<string>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<cstdio>
 8 using namespace std;
 9
10 string s[15];
11 string ans[305];
12 int main(){
13
14     int n;
15     string str;
16     while(cin>>n){
17         for(int i=1;i<=n;i++){
18             cin>>s[i];
19         }
20         int coun=0;
21         int len=s[1].length();
22         int num=1<<len;
23         for(int i=1;i<num;i++){
24             int j=i;
25             str="";
26             for(int k=0;k<len;k++){
27                 if((j>>k)&1){
28                     str+=s[1][k];
29                 }
30             }
31             int co=0;
32             for(int k=1;k<=n;k++){
33                 for(int h=0;h<s[k].length();h++){
34                     int len1=str.length();
35                     int len2=s[k].length();
36                     int l1=0,l2=0;
37                     while(l1<len1&&l2<len2){
38                         if(str[l1]==s[k][l2]){
39                             l1++;
40                             l2++;
41                         }
42                         else{
43                             l2++;
44                         }
45                     }
46                     if(l1==len1){
47                         co++;
48                         break;
49                     }
50                     char hh=s[k][0];
51                     s[k]=s[k].substr(1);
52                     s[k]+=hh;
53                 }
54                 if(co==n){
55                     ans[coun++]=str;
56                 }
57             }
58         }
59         int prelen=0;
60         if(coun==0){
61             cout<<0<<endl;
62         }
63         else{
64             for(int i=0;i<coun;i++){
65                 if(prelen<ans[i].length()){
66                     prelen=ans[i].length();
67                 }
68             }
69             string aa;
70
71             for(int i=0;i<coun;i++){
72                 if(prelen==ans[i].length()){
73                     aa=ans[i];
74                     break;
75                 }
76             }
77             string pre="zzzzzzzzzzzz";
78             for(int i=0;i<aa.length();i++){
79                 char tmp=aa[0];
80                 aa=aa.substr(1);
81                 aa+=tmp;
82                 if(pre>aa){
83                     pre=aa;
84                 }
85             }
86             cout<<pre<<endl;
87         }
88
89     }
90
91 }

View Code

 

转载于:https://www.cnblogs.com/Fighting-sh/p/9718042.html

Tomb Raider(暴力模拟)相关推荐

  1. HihoCoder - 1829 Tomb Raider(暴力)

    题目链接:点击查看 题目大意:给出n个环形字符串,求n个字符串的最大公共子序列,如果有多个长度相同的答案,输出字典序最小的 题目分析:这个题数据给的很小,n只有10,字符串的长度只有8,所以可以直接暴 ...

  2. hihoCoder-1829 2018亚洲区预选赛北京赛站网络赛 B.Tomb Raider 暴力 字符串

    题面 题意:给你n个串,每个串都可以选择它的一个长度为n的环形子串(比如abcdf的就有abcdf,bcdfa,cdfab,dfabc,fabcd),求这个n个串的这些子串的最长公共子序列(每个串按顺 ...

  3. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举)

    #1829 : Tomb Raider 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, the fiercely independent daugh ...

  4. 【2018.3.24】模拟赛之四-ssl2548 旋转【暴力模拟】

    正题 大意 给出一块黑块和白块组成的版,将其旋转90°后和之前的黑块叠加,求最初始和每次旋转后的黑块数. 解题思路 暴力模拟不解释 代码 #include<cstdio> #include ...

  5. HLJUOJ1117(暴力模拟)

    八数码 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 109  Solved: 19 [Submit][Status][Web Board] Desc ...

  6. 牛客小白月赛28 E-会当凌绝顶,一览众山小 线段树+二分暴力模拟

    牛客小白月赛28 E-会当凌绝顶,一览众山小 线段树+二分暴力模拟 题意 思路 Code 传送门: https://ac.nowcoder.com/acm/contest/16081/E 题意 登山顺 ...

  7. 【暴力+模拟】HDU-1346 Coconuts, Revisited

    注解 1.暴力模拟,从题目给定的数目减一开始枚举人数,直到人数只有1人为止.最先找到的满足题目要求的人数,就是答案. 代码 #include <iostream>using namespa ...

  8. 365. 水壶问题-暴力模拟倒水过程-递归法

    365. 水壶问题-暴力模拟倒水过程-递归法 有两个水壶,容量分别为 jug1Capacity 和 jug2Capacity 升.水的供应是无限的.确定是否有可能使用这两个壶准确得到 targetCa ...

  9. 树上问题 ---- E. Fib-tree(斐波那契数的性质 + 暴力模拟 + 认真计算复杂度)

    题目大意: 一个树是FIBFIBFIB树得是节点个数为斐波那契数,且(注意这个且)!!此外满足下面条件一个: 1.只有一个点 2.可以切一条边使得分出的两个子树都是FIBFIBFIB树. 给你一棵树, ...

  10. 51nod 1414 冰雕 思路:暴力模拟题

    题意是现在有n个雕像把一个圆等分了,每一个雕像有一个吸引力. 叫你不移动雕像只去掉雕像让剩下的雕像还能等分这个圆,求剩下的雕像的吸引力之和的最大值. 显然去掉后剩下雕像的间隔应该是n的因子,因为这样才 ...

最新文章

  1. C语言从青铜到王者——数组详解总结【一维数组、二维数组、字符数组、数组实例】
  2. Redis的安装与简单部署
  3. 一篇万字长文读懂微软PDB、SourceLink——.net core之nuget 包调试
  4. 实验 使用 vivado zedboard GPIO 开关 开控制 LED
  5. μC/OS-II实时性能测试与分析
  6. 如何评价百度新目标:Everyone can AI ?| 在现场
  7. NERDTree 快捷键辑录
  8. ubuntu搭建Kubernetes集群(ansible,kubedam,rancher)
  9. Linux 设置交换分区
  10. CS231n李飞飞计算机视觉 神经网络训练细节part2下
  11. 360搭建windows补丁服务器
  12. 使用Python websockets搭建互联网服务器
  13. 百度离线地图-加载地图(一)
  14. 网络七层协议和TCP/IP五层协议
  15. 自签名证书和私有CA签名的证书的区别
  16. 山东大学软件学院2021软件项目管理考试回忆
  17. 网卡MAC地址是什么?
  18. 【Python军火库】pyautogui:成熟的鼠标和键盘自己动起来!
  19. 人工智能专业就业方向及就业前景分析
  20. 加密听证会观点概览,美国监管首次强调Web3.0是未来

热门文章

  1. [TeXPage] 打造好用的 LaTeX 在线编辑器
  2. Ubuntu下ASIC/FPGA环境搭建
  3. java 大于或等于_java大于等于怎么表示
  4. R语言ggplot2可视化在轴标签、轴标题中添加大于号、等于号等实战
  5. iphone个系列尺寸_iPhone所有机型对比尺寸
  6. vue.js根据数据循环生成表格_Vue Elenent实现表格相同数据列合并
  7. 怎么查看oracle是多少位的,查看 Oracle 是32位还是64位的方法
  8. bp神经网络是前馈网络吗,什么是前馈神经网络
  9. 了解talkingData
  10. Unity接TalkingData自动集成XCode