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个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...
随机推荐
- [CentOS7] firewalld重启失败 Failed to start firewalld - dynamic firewall daemon.
错误信息: Failed to start firewalld - dynamic firewall daemon. 如图: 解决方法: 也就是kernel不支持现在的firewall防火墙的某些模块 ...
- 飘逸的python - @staticmethod和@classmethod的作用与区别
一般来说,要使用某个类的方法,需要先实例化一个对象再调用方法. 而使用@staticmethod或@classmethod,就可以不需要实例化,直接类名.方法名()来调用. 这有利于组织代码,把某些应 ...
- Spark 中的 RPC 的几个类
Spark 中 RPC 部分的涉及了几个类,有点晕,在此记录一下 1. RpcEndpoint: RPC的一个端点.给定了相应消息的触发函数.保证 `onStart`, `receive` and ...
- puppet批量管理500多台服务器
前言 puppet使用了有一段时间了,之前写的手顺书一直未发布到blog上来,今天正好有空,写下一点笔记.公司在用的服务器有500多台,基本都为CentOS,版本有5和6两种,管理起来很不方便,尤其是 ...
- any cpu ×86 ×64
On a 32-bit machine: Any CPU: runs as a 32-bit process, can load Any CPU and x86 assemblies, will ge ...
- django的models字段介绍
#增加数据库数据方法#方法1CalcData.objects.create(var1 ='21',var2='22')#方法2obj =CalcData(var1 ='21',var2='22')jo ...
- mysql之SQL入门与提升(二)
在mysql之SQL入门与提升(一)我们已经有了些许基础,今天继续深化 先造表 SET NAMES utf8;SET FOREIGN_KEY_CHECKS = 0; -- -------------- ...
- 关于json_encode和json_decode
json_encode将数组或者对象编码成字符串json_deode将字符串解码称对象或者数组,第二个参数为true时解码成字符串,否则解码成对象
- CentOS下ganglia监控部署
第一步:CentOS环境准备 1.yum -y install apr-devel apr-util check-devel cairo-devel pango-devel libxml2-devel ...
- 3Ds Max FTL:Virtual device creation failed.
1.在安装完成并激活3DsMax2017中文版后,启动提示:渲染错误消息:FTL: Virtual device creation failed.(中文译:虚拟设备的创建失败). 2.关闭渲染错误消息 ...