hdu1238--Substrings
暴力求解
题意:求一个公共子串的最大长度,反转的公共子串存在也算。
求解思路:先找出最短的字符串进行暴力枚举。每截取一个子串后,求出它的反转字符串,然后检验这两个子字符串是否存在输入的字符串组中,每个字符串只要存在子字符串和的翻转串其中一个就行。
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
#define max(a,b) a>b?a:b int n,len,id;
string str[];
bool check(string sub)
{
string tmp;
int sl=sub.size();
for(int i=;i<sl;i++)
tmp+=sub[sl--i];
for(int i=;i<n;i++)
if(str[i].find(sub)==str[i].npos && str[i].find(tmp)==str[i].npos)
return false;
return true;
}
void Deal()
{
int ans=;
string tmp;
for(int i=;i<str[id].size();i++)
for(int j=str[id].size()-;j>=i;j--)
{
if((j-i+)<ans) continue;
tmp=str[id].substr(i,j-i+);
if(check(tmp))
ans=max(ans,(j-i+));
}
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
len=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>str[i];
if(str[i].size()<len)
{
len=str[i].size();
id=i;
}
}
Deal();
}
}
hdu1238--Substrings的更多相关文章
- HDU-1238 Substrings
Substrings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- hdu1238 Substrings (暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=1238 Substrings Time Limit : 2000/1000ms (Java/Other) Me ...
- hdu1238 Substrings 扩展KMP
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- KMP 、扩展KMP、Manacher算法 总结
一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 P ...
- Substrings(hdu1238)字符串匹配
Substrings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
随机推荐
- Android 查看通讯录Contacts是否发生变化
目的:确定通讯录是否发生变化 根据:參见ContactsContract.RawContacts类中的VERSION常量,该值是仅仅读的,当通讯录发生变化时,都会使该值变化 方法:version值是相 ...
- 搭建PhoneCat项目的开发与测试环境
AngularJS官方网站提供了一个用于学习的示例项目:PhoneCat.这是一个Web应用,用户可以浏览一些Android手机,了解它们的详细信息,并进行搜索和排序操作. 获取源代码 PhoneCa ...
- asp.net生成缩略图、文字图片水印
/// <summary> /// 会产生graphics异常的PixelFormat /// </summary> private static PixelFormat[] ...
- currentStyle、getComputedStyle
element.offsetWidth: 返回元素的宽度,包括边框和内边距. element.offsetHeight: 返回元素的高度,包括边框和内边距. currentStyle: 获取计算后的样 ...
- 使用html,JavaScript,ajax写一个小型实例
//1.创建受捐单位数组 var arrOrgData = [ { "Id": 1, "OrgName": "红十字会" }, ...
- LVS客户端启动脚本
在设置LVS客户端时,如果我们使用手工设置的话会比较麻烦.现在我们直接使用脚本来启动lvs-client就OK了,下面是一个简单的脚本. VIP地址:10.0.0.230,把文件放到/etc/init ...
- Weex 开发入门
去年也听说过 React Native 技术,现在好像很多大公司都在这套技术中踩坑,在开发自己的UI.工作中涉及不到,一直没有学习相关的知识. 并且听说阿里的 vue native,一直很期待.前段时 ...
- VS2008 自定义向导的default.js设置(DLL文件)
function OnFinish(selProj, selObj) { try { var strProjectPath = wizard.FindSymbol('PROJECT_PATH'); v ...
- IBM developerWorks 的Ajax系列教程
掌握 Ajax,第 1 部分: Ajax 入门简介 http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro1.html?csrf-799150205 ...
- CSS预处理器实践之Sass、Less比较
什么是CSS预处理器? CSS可以让你做很多事情,但它毕竟是给浏览器认的东西,对开发者来说,Css缺乏很多特性,例如变量.常量以及一些编程语法,代码难易组织和维护.这时Css预处理器就应运而生了.Cs ...