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的更多相关文章
随机推荐
- 452. Remove Linked List Elements【Naive】
Remove all elements from a linked list of integers that have value val. Example Given 1->2->3- ...
- 01、Windows Phone 套接字(Socket)实战之交互设计
这个 Demo 主要使用 WP 中提供的 Socket 对象,来与 PC 端进行文字.文件的互相传输.因为在 WP 中系统 对存储的操作限制的比较多,例如,你把 .doc..txt..zip 等常见的 ...
- CentOS 6.2修改主机名
写在前面的话:因为服务器要统一主机名,但是在安装的时候忘记设置了,所以需要修改主机名 需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会 ...
- c语言中struct的内存对齐
为了让CPU能够更舒服地访问到变量,struct中的各成员变量的存储地址有一套对齐的机制.这个机制概括起来有两点:第一,每个成员变量的首地址,必须是它的类型的对齐值的整数倍,如果不满足,它与前一个成员 ...
- hdu1978(记忆化搜索)
#include<iostream> #include<stdio.h> #include<string.h> #include<queue> usin ...
- windows测试模式
测试模式通常意义就是让windows 操作系统在测试状态下运行,windows操作系统在这种模式下可以运行非官方或无数字签名的驱动程序 . 目录 1 定义 2 进入/退出windows测试模式方法 ...
- spring中事务传播解读:PROPAGATION_REQUIRES_NEW
第一步:获取事务状态,判断当前事务线程是否存在.第二步:如果当前事务的传播行为为PROPAGATION_REQUIRES_NEW,挂起当前线程绑定的事务,取消当前事务的sessionHolder和co ...
- Excel 自定义关闭按钮
遇到过这样一个需求,是在excel关闭的时候,不要excel本身的保存窗口,只用自定义的. 这个的需要第一,是点击关闭时候触发, 第二:触发后,不能还是弹出那个窗口 第三:取消后,要能停止程序 为了弄 ...
- oozie开发注意事项
ooziejob执行后 1. job.properties.coordinatior.xml中设置的值都是不可变的,除非将job kill掉,然后重新调度. oozie job -kill 00000 ...
- SSIS 自测题-文件操作类
说明:以下是自己的理解答案,不是标准的答案,如有不妥烦请指出. 有些题目暂时没有答案,有知道的请留言,互相学习,一起进步. 1.什么是控制流,什么是数据流,控制流和数据流之间的关系是什 ...