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个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...
随机推荐
- remap——ROS中修改订阅的节点名称
跑数据集或者使用不同传感器时,难免会遇到需要修改topic名称的时候,此时可以有两种做法. 一.直接修改源码.如果有launch文件,则修改launch文件对应的topic 二.直接进行remap操作 ...
- Java8 使用 stream().sorted()对List集合进行排序
集合对像定义 集合对象以学生类(StudentInfo)为例,有学生的基本信息,包括:姓名,性别,年龄,身高,生日几项. 使用stream().sorted()进行排序,需要该类实现 Comparab ...
- Spark TaskScheduler 概述
TaskScheduler 原理: 1. DAGScheduler 在提交Taskset给底层调度器的时候是面向接口TaskScheduler的, 这符合面向对象中依赖抽象原则,带来底层资源调度器的可 ...
- Eclipse项目中乱码问题的解决办法
一.产生的原因: 1.Http协议进行通信的时候是基于请求和响应的,传输的内容我们称之为报文! 2.Http协议会按照一定的规则将报文编码,然后在读取的时候再使用响应的解码格式进行解码! 3.这个一定 ...
- Docker从入门到实战(四)
Docker基础 一:Docker基本操作 一般情况安装Docker之后系统会自动创建一个Docker的用户组,如果没有创建可以手动创建groupadd docker把当前非root用户加入group ...
- An internal error occurred during: "Add Deployment". Container with path org.eclipse.jdt.launching.
导入非本机项目出现这种错误,原因就是JDK版本不一致. 具体解决步骤如下: 右键项目名→Properties→JavaBuild Path→Libraries→选中JRE SystemLibrary[ ...
- WSGI学习系列eventlet.wsgi
WSGI是Web Service Gateway Interface的缩写. WSGI标准在PEP(Python Enhancement Proposal)中定义并被许多框架实现,其中包括现广泛使用的 ...
- (转)linux自定义开机启动服务和chkconfig使用方法
原文:https://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html linux自定义开机启动服务和chkconfig使用方法 1. 服 ...
- IDEA/Eclipse安装 Alibaba Java Coding Guidelines 插件
为了让开发者更加方便.并且达到快速规范代码格式的目的并实行起来,阿里巴巴基于<阿里巴巴Java开发规约>手册内容,研发了一套自动化的IDE检测插件(IDEA.Eclipse).它就是Ali ...
- Have启动报错:java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
错误日志如下: [hadoop@master hive1.0.0]$ bin/hive Logging initialized using configuration in file:/opt/mod ...