POJ3080Blue Jeans(暴力)
开始做字符串专题,地址
第一题水题,暴力就可以做
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define lson k<<1, L, mid
#define rson k<<1|1, mid+1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FOPENIN(IN) freopen(IN, "r", stdin)
#define FOPENOUT(OUT) freopen(OUT, "w", stdout) template<class T> T CMP_MIN(T a, T b) { return a < b; }
template<class T> T CMP_MAX(T a, T b) { return a > b; }
template<class T> T MAX(T a, T b) { return a > b ? a : b; }
template<class T> T MIN(T a, T b) { return a < b ? a : b; }
template<class T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<class T> T LCM(T a, T b) { return a / GCD(a,b) * b; } //typedef __int64 LL;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
const double eps = 1e-; char str[][], ansStr[];
int T, N; int maxLen(char* s1, char* s2)
{
int ans = ;
for(int i=;s2[i];i++)
{
int len = ;
for(int j=;s1[j];j++)
{
if(s2[i+j] == s1[j]) len++;
else break;
}
ans = max(ans, len);
}
return ans;
} int main()
{
while(~scanf("%d", &T))while(T--)
{
mem0(str); mem0(ansStr);
scanf("%d%*c", &N);
for(int i=;i<N;i++) scanf("%s", str[i]);
int ans = ;
for(int i=;str[][i];i++)
{
int len = INF;
for(int j=;j<N;j++)
{
len = min( len, maxLen(&str[][i], str[j]) );
}
if(ans < len)
{
ans = len;
for(int j=i;j<i+ans;j++) ansStr[j-i] = str[][j];
ansStr[i+ans] = ;
}
else if(ans == len)
{
int ok = ;
for(int j=;j<ans;j++)
{
if(ok) ansStr[j] = str[][i+j];
else if(ansStr[j] != str[][i+j])
{
if(ansStr[j] < str[][i+j]) break;
else { ansStr[j] = str[][i+j]; ok = ; }
}
}
}
}
if(ans >= )
printf("%s\n", ansStr );
else printf("no significant commonalities\n");
}
return ;
}
POJ3080Blue Jeans(暴力)的更多相关文章
- POJ-3080-Blue jeans(KMP, 暴力)
链接: https://vjudge.net/problem/POJ-3080#author=alexandleo 题意: 给你一些字符串,让你找出最长的公共子串. 思路: 暴力枚举第一个串的子串,挨 ...
- POJ3080——Blue Jeans(暴力+字符串匹配)
Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...
- POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()
题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ3080Blue Jeans
http://poj.org/problem?id=3080 题意 : 给你几个DNA序列,让你找他们的共同的最长的子串,若是子串长度小于3,就输出no significant commonaliti ...
- poj3080Blue Jeans(在m个串中找到这m个串的 最长连续公共子序列)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- poj 3080 Blue Jeans (暴力枚举子串+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- 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. 最长公共 ...
- poj3080 Blue Jeans【KMP】【暴力】
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions:21746 Accepted: 9653 Descri ...
随机推荐
- 【同行说技术】swift最全学习资料汇集(一)
Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序.2015年12月4日,苹果公司宣 ...
- 移植linux(1)
硬件环境:TQ2440 软件环境:linux-2.6.30.4 下载源码:ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.4.tar ...
- I.MX6 Android backlight modify by C demo
/************************************************************************** * I.MX6 Android backligh ...
- 对于fmri的设计矩阵构造的一个很直观的解释-by 西南大学xulei教授
本程序意在解释这样几个问题:完整版代码在本文的最后. 1.实验的设计如何转换成设计矩阵? 2.设计矩阵的每列表示一个刺激条件,如何确定它们? 3.如何根据设计矩阵和每个体素的信号求得该体素对刺激的敏感 ...
- valueOf intValue parsetInt区别
1.int intValue() 以 int 类型返回该 Integer 的值. Long l = 123; l.intValue() ---->int : 123 2.static int p ...
- linux上改变mysql数据文件的位置
用软连接改变了/var/lib/mysql的位置,并设置好mysql.mysql的权限,但是发现还是不能启动. 发现/var/log/mysqld.log 150308 16:16:02 [Warni ...
- 剑指offer-第三章高质量的代码(调整数组顺序使得奇数位于偶数的前面)
题目:输入一个整数数组,实现一个函数中调整该数组中数字的顺序,使得所有的奇数位于数组的前半部,所有偶数位于数组的后半部. 思路:用两个指针p1和p2,分别指向数组的头和尾部,p1只向后移,p2只向前移 ...
- photoshop,用切片工具等分图片
一,切片 二,导出: 菜单->文件->存储为Web和设备所用格式 将预设改为PNG-24,然后点存储.
- Javascript中的Keycode值列表
关于如何得到一个键在Javascript中的Keycode值,可以参考: <body onkeypress=alert(event.keyCode)>请按任意键,你将得到该键的键值! ke ...
- 关于asp.net中页面事件加载的先后顺序
一.ASP.NET 母版页和内容页中的事件 母版页和内容页都可以包含控件的事件处理程序.对于控件而言,事件是在本地处理的,即内容页中的控件在内容页中引发事件,母版页中的控件在母版页中引发事件.控件事件 ...