HDOJ 题目5510 Bazinga(瞎搞)

Bazinga

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 331    Accepted Submission(s): 139


Problem Description
Ladies and gentlemen, please sit up straight.
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 (1in) such that there exists an integer j (1j<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".
 

Input
The first line contains an integer t (1t50) which is the number of test cases.
For each test case, the first line is the positive integer n (1n500) 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.
 

Output
For each test case, output the largest label you get. If it does not exist, output 1 .
 

Sample Input
  
  
4 5 ab abc zabc abcd zabcd 4 you lovinyou aboutlovinyou allaboutlovinyou 5 de def abcd abcde abcdef 3 a ba ccc
 

Sample Output
  
  
Case #1: 4 Case #2: -1 Case #3: 4 Case #4: 3
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5539  5538  5537  5536  5535 
 题目大意:就是让你找一个最大的i,是的最少存在一个0<j<i,字符串数sj不是si的子串
沈阳区域赛的题,太弱,并没有沈阳区域赛的资格,做重现的时候,感觉这个题不会很简单,就硬生生的写了200来行的在线ac自动机,,,死活超时。。原本想放弃了,看到讨论区里有说有简单地方法,可以用strstr过,于是就想了想,暴力肯定超时,它是从上往下有积累的很多串已经是一个串的子串了,和这个串比了,就没必要再和他的子串比了,,于是一顿瞎搞就过了。。第六,,
ac代码
1Hacker_vision156MS2648K1477BG++2015-10-31 18:00:50
2_JM171MS2672K1135BG++2015-10-31 17:53:30
3戦い218MS2624K1539BG++2015-10-31 21:54:18
4马孟起249MS2644K1040BG++2015-11-01 13:59:16
5preserve265MS2672K1026BC++2015-11-01 11:19:40
6XY_280MS2716K729BC++2015-11-01 20:41:08
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
char str[505][2002];
int next[2002];
int cc[505];
int n,m;
int main()
{
    int t,c=0;
    scanf("%d",&t);
    while(t--)
    {
        int num;
        scanf("%d",&num);
        int i,j,k;
        for(i=1;i<=num;i++)
            scanf("%s",str[i]);
        int ans=-1;
        int flag=0;
        for(i=num;i>1;i--)
            if(!strstr(str[i],str[i-1]))
            {
                ans=max(ans,i);
                for(j=i-1,k=i+1;k<=num;k++)
                    if(!strstr(str[k],str[j]))
                        ans=max(ans,k);
            }
        printf("Case #%d: %d\n",++c,ans);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值