HDU_5510_Bazinga
Bazinga
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 5056 Accepted Submission(s): 1596
Don't tilt your head. I'm serious.

For n given strings S1,S2,⋯,Sn, labelled from 1 to n, you should find the largest i (1≤i≤n) such that there exists an integer j (1≤j<i) and Sj is not a substring of Si.
A substring of a string Si is another string that occurs in Si. For example, ``ruiz" is a substring of ``ruizhang", and ``rzhang" is not a substring of ``ruizhang".
For each test case, the first line is the positive integer n (1≤n≤500) and in the following n lines list are the strings S1,S2,⋯,Sn.
All strings are given in lower-case letters and strings are no longer than 2000 letters.
5
ab
abc
zabc
abcd
zabcd
4
you
lovinyou
aboutlovinyou
allaboutlovinyou
5
de
def
abcd
abcde
abcdef
3
a
ba
ccc
Case #2: -1
Case #3: 4
Case #4: 3
- 找到最大ID字符串i使得存在j<i的字符串不是i的子串
- 首先考虑如果从l到r串都满足都是r的子串,那么k>r串只需要检测r串即可
- 如果自l串开始到l+k串都是存在小于l的串不是当前串子串,那么对于l+k+1串就要检测l-1串和l到l+k串
- 算法出来了,就是记录当前最大id使得此id之前全是id串的子串,然后检测串的范围就是这个id到当前ID的前一位
- 如果用这样的算法,用c的strstr即可,用kmp可以减少一半时间
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; int T, n, use[maxn], mx, ans;
char s[][];
std::vector<int> v;
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d",&T)){
for(int kase=;kase<=T;kase++){
ans=-;
scanf("%d",&n);
mx=;
use[]=;
v.clear();
scanf("%s",s[]);
for(int i=;i<=n;i++){
scanf("%s",s[i]);
int flag=;
if(strstr(s[i],s[mx])==NULL)
flag=;
if(flag&&use[i-]){
for(int j=v.size()-;j>= && flag;j--){
if(strstr(s[i],s[v[j]])==NULL)
flag=;
}
}
if(flag){
mx=i; use[i]=; v.clear();
}else{
ans=i; use[i]=; v.push_back(i);
}
} printf("Case #%d: %d\n",kase,ans);
}
}
return ;
}
HDU_5510_Bazinga的更多相关文章
随机推荐
- Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 33554432 bytes
MongoDB执行错误: Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 335 ...
- lua urlencode urldecode URL编码
URL编码其实就是对一些字符转义为%加上该字符对应ASCII码的二位十六进制形式. 如: 字符 特殊字符的含义 URL编码 # 用来标志特定的文档位置 % % 对特殊字符进行编码 % & 分隔 ...
- 动态修改 dom 元素的伪类样式
最近写代码,需要修改伪类的 content 属性,不想定义两个样式进行切换,而是直接通过 js 进行修改. html 中的伪类(如 a:hover / a:link / class::before / ...
- Lucene:基于Java的全文检索引擎简介 (zhuan)
http://www.chedong.com/tech/lucene.html ********************************************** Lucene是一个基于Ja ...
- 整合hibernate的lucene大数据模糊查询
大数据模糊查询lucene 对工作单使用 like模糊查询时,实际上 数据库内部索引无法使用 ,需要逐条比较查询内容,效率比较低在数据量很多情况下, 提供模糊查询性能,我们可以使用lucene全文 ...
- node js 调试出现同一个端口启动多次报错处理方案 Error: listen EADDRINUSE
windows 下 1.查询端口占用的进程ID: netstat -aon | findstr "80" 80为端口号, 输出为: TCP 0.0.0.0:3000 ...
- Bootstrap学习笔记(7)--轮播
说明: 1. 幻灯片效果,外面的div有个id="myppt",class="carousel slide"这个是有图片滑动效果,不加就是直接瞬间换图片,dat ...
- 基于html5制作3D拳击游戏源码下载
今天给大家分享一款基于HTML5实现的3d拳王游戏源码.这款实例适用浏览器:360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. 不支持IE8及以下浏览器. 在线预览 ...
- Flume Channel Selectors + kafka
http://flume.apache.org/FlumeUserGuide.html#custom-channel-selector 官方文档上channel selectors 有两种类型: Re ...
- spring boot初步尝试
第一次知道spring boot这个项目是为在学习spring的时候,在官网上看到的,那个时候不知道这个项目是干嘛的,也就没再继续关注了 这些天实习没什么事做,一直没用spring框架了,就想着去官网 ...