POJ-3080 Blue Jeans---字符串+暴力
题目链接:
https://vjudge.net/problem/POJ-3080
题目大意:
找最长的公共字串(长度>=3),长度相同就找字典序最小的
解题思路:
枚举第一个串的所以子串,处理出其他串的所有子串,然后set查找,更新ans
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
int T;
set<string>tot[];
int main()
{
cin >> T;
while(T--)
{
int n;
string s, s1;
cin >> n;
cin >> s;
for(int i = ; i < n; i++)
{
cin >> s1;
tot[i].clear();
for(int len = ; len <= s1.size(); len++)
{
for(int start = ; start + len <= s1.size(); start++)
{
int end = start + len;
string s2;
for(int j = start; j < end; j++)
s2 += s1[j];
tot[i].insert(s2);
}
}
}
string ans = "";
for(int len = ; len <= s.size(); len++)
{
for(int start = ; start + len <= s.size(); start++)
{
int end = start + len;
string s2;
for(int i = start; i < end; i++)
s2 += s[i];
bool flag = ;
for(int i = ; i < n; i++)
{
if(!tot[i].count(s2))
{
flag = ;
break;
}
}
if(flag)
{
if(s2.size() > ans.size())
{
ans = s2;
}
else if(s2.size() == ans.size() && ans > s2)
{
ans = s2;
}
}
}
}
if(ans.size() < )cout<<"no significant commonalities"<<endl;
else cout<<ans<<endl;
}
}
POJ-3080 Blue Jeans---字符串+暴力的更多相关文章
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- POJ 3080 Blue Jeans(Java暴力)
Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- POJ 3080 Blue Jeans (多个字符串的最长公共序列,暴力比较)
题意:给出m个字符串,找出其中的最长公共子序列,如果相同长度的有多个,输出按字母排序中的第一个. 思路:数据小,因此枚举第一个字符串的所有子字符串s,再一个个比较,是否为其它字符串的字串.判断是否为字 ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
- poj 3080 Blue Jeans (暴力枚举子串+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)
<题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1. 最长公共串长度小于3输出 no significant co ...
- POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1
题目 http://poj.org/problem?id=3080 题意 有m个(2<=m<=10)不包含空格的字符串,长度为60个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...
随机推荐
- Highest Price in Supply Chain (25)(DFS)(PAT甲级)
#include<bits/stdc++.h>using namespace std;int fa;int degree[100007];vector<int>v[100007 ...
- Git 撤销中间某次的提交记录
今天遇到一个问题,一周前一位同事把非发布代码合并到发布分支上并已发布线上,在这个提交点后已经有了很多次的提交记录,所以不能直接回滚,使用到了gIt提供的revert.以此记录. git revert ...
- Vue源码学习之数据初始化
首发地址:CJWbiu's Blog 在这里思考一个问题,使用Vue的时候需要在创建Vue实例时传入一个option,这里包含了我们定义的props.methods.data等.而在methods的方 ...
- mac终端快捷键
mac终端快捷键: http://www.jianshu.com/p/e6c364084c22
- Options Menu的android3.0以上和以下版本显示刷新原理,刷新适配
一 显示区别: 2.3.x及以下版本,需要按菜单键显示菜单,当菜单打开时,第一个可见的部分是图标菜单,最多可容纳6个菜单项.如果你的菜单包括Android的地方超过6项,第六项,其余将被归到”More ...
- (转)/etc/sysctl.conf 调优 & 优化Linux内核参数
/etc/sysctl.conf 调优 & 优化Linux内核参数 from: http://apps.hi.baidu.com/share/detail/15652067 http://ke ...
- 三节点Hadoop集群搭建
1. 基础环境搭建 新建3个CentOS6.5操作系统的虚拟机,命名(可自定)为masternode.slavenode1和slavenode2.该过程参考上一篇博文CentOS6.5安装配置详解 2 ...
- discuz迁移到虚拟空间后无法上传图片的问题
discuz X3迁移到虚拟空间后无法上传图片,提示"附件无法保存": 解决方法: 1.看看虚拟空间的容量是不是满了. 2.登录管理员后台,工具->更新缓存.
- codesmith 在安装32位Oracle 客户端问题解决
问题解决办法如下: https://blog.csdn.net/csdn1152789046/article/details/52248669
- 如何处理HTML标签属性
在jQuery里我们可以通过.attr()的方法来实现对HTML标签属性(tag attribute)处理. 1. 获取标签属性的值 (演示) 语法:$('选定目标').attr('属性名') 例子如 ...