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的更多相关文章
随机推荐
- [svc]执行sudo时报错:effective uid is not 0
http://jingyan.baidu.com/article/c45ad29cd83d4b051753e232.html 今天将 / 授权给了一个普通用户 导致一些问题. 启事: 操作前一定要先在 ...
- mount -o remount,rw / (这是个求命的命令)
当系统无法启动的时候.我们会前进入单用户模式(正常情况下单用户莫式是权限是正常的,只在在无法启动的情况下, 再进入单用户模式,权限才会是只读),这时候没有对文件的修改权限(所有的文件都是只读) 用这条 ...
- location [=|$|最长原则|^~](nginx-1.4.4)
优先级由上到下依次递减: location =/a/1.png { return 400; } } location ~* \.png$ { return 403; } location /a/1.p ...
- cookie,session,localStage,sessionStage区别
Cookie和Session详解 1.什么是Cookie Cookie是存放在客户端浏览器的Name/Value键值对,访问服务器时,会自动传递给服务器. Cookie的生成方式有两种,服务器写入,客 ...
- 本次安装Lion记录
黑苹果驱动之家 http://it360.org.cn/ Mac安装在Macintosh上是没什么好讲的,也没什么难度,原生的东西.但每次Mac安装在PC上总能折腾一番,驱动.五国.各种报错..今天记 ...
- msf提权命令/meterpreter下的几个命令
废话: 今天本来日学校内网.以为是台08.结果稀里糊涂居然日了宿舍哥们儿的PC机.按道理都该装杀毒的才对,我舍友都不装的.裸装上阵说的就是我舍友了.劝各位大佬.把杀毒装好.补丁打好. 通过这次我也学到 ...
- 5分钟用Spring4 搭建一个REST WebService(转)
章节目录 前置技能 新建项目,配置依赖文件 编写Model和Controller 启动服务&访问 但是 其他 前置技能 ① 使用maven来管理java项目 这个技能必须点一级,以便快速配置项 ...
- [driver]linux内核动态加载模块
问题: 1. 把编译好的模块放到板子/lib/modules对应文件夹下,并且执行了depmod -a, 比如pl2303.ko, 那么下一次插入pl2303的串口线,是否可以识别,也就是自动加载pl ...
- java线程池的应用浅析
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java ...
- RP2836 OUT0-OUT7 对应关系
ARM-IO9 OUT0 PA8 备用 P5-A4管脚,可以连接74HC164D级联 ARM-IO10 OUT7 PA1 3 ...