Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5510
The General Assembly will be tle, for noble and look-up.
1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> + - using namespacestd; + A Const intMAXN =510; at Const intMAXM =2020; - intN, ans; - intLEN[MAXN]; - CharS[MAXN][MAXM]; - Set<int>REP[MAXN]; - inInlineBOOLScan_d (int&num) { - Char inch;BOOLisn=false; to inch=GetChar (); + if(inch==eof)return false; - while(inch!='-'&& (inch<'0'||inch>'9'))inch=GetChar (); the if(inch=='-') {isn=true; num=0;} * Elsenum=inch-'0'; $ while(inch=getchar (),inch>='0'&&inch<='9'){Panax Notoginsengnum*=Ten, num+=inch-'0'; - } the if(IsN) num=-num; + return true; A } the + intMain () { - //freopen ("in", "R", stdin); $ intT, _ =1; $ Scan_d (T); - while(t--) { -Ans =0; thememset (s),0,sizeof(s)); -memset (Len,0,sizeof(len));Wuyi Scan_d (n); the for(inti =1; I <= N; i++) { -scanf"%s", S[i]); Wu rep[i].clear (); - } About intAns =-1; $ for(inti =1; I <= N; i++) { - for(intj = i-1; J >=1; j--) { - if(Len[i] < len[j])Continue; - if(Rep[i].find (j)! = Rep[i].end ())Continue; A if(Strstr (S[i], s[j])! =NULL) { + Rep[i].insert (j); the } - Else { $Ans =i; the Break; the } the } the } -printf"Case #%d:%d\n", _++, ans); in } the return 0; the}
TLE
1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> + - using namespacestd; + A Const intMAXN =510; at Const intMAXM =2020; - intN, ans; - intPRE[MAXN]; - intLEN[MAXN]; - CharS[MAXN][MAXM]; - in intFindintx) { - returnx = = Pre[x]? X:PRE[X] =find (Pre[x]); to } + BOOLCheckintXinty) { -x =find (x); they =find (y); * if(x = = y)return 1; $ return 0;Panax Notoginseng } - the intMain () { + //freopen ("in", "R", stdin); A intT, _ =1; thescanf"%d", &T); + while(t--) { -Ans =0; $memset (s),0,sizeof(s)); $memset (Len,0,sizeof(len)); -scanf"%d", &n); - for(inti =1; I <= N; i++) { thescanf"%s", S[i]); - }Wuyi for(inti =1; I <= N; i++) { thePre[i] =i; - } Wu intAns =-1; - for(inti =1; I <= N; i++) { About for(intj = i-1; J >=1; j--) { $ if(Len[i] < len[j])Continue; - if(Check (i, j))Continue; - if(Strstr (S[i], s[j])! =NULL) { -Pre[i] =J; A } + Else { theAns =i; - Break; $ } the } the } theprintf"Case #%d:%d\n", _++, ans); the } - return 0; in}
[HDOJ5510] Bazinga (and collection)