标签:tms java mem namespace bre out any stream scan
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1238
枚举最短字符串的的每个子串然后暴力。。。。我能怎么办,我也很无奈啊
代码:
1 #define _CRT_SECURE_NO_WARNINGS
2 #include <functional>
3 #include <algorithm>
4 #include <iostream>
5 #include <cstring>
6 #include <cassert>
7 #include <cstdio>
8 #include <cctype>
9 #include <vector>
10 #include <string>
11 #include <queue>
12 #include <stack>
13 #include <cmath>
14 #include <map>
15 #include <set>
16 using namespace std;
17 #define rep(i,a,n) for (int i=a;i<n;i++)
18 #define per(i,a,n) for (int i=n-1;i>=a;i--)
19 #define pb push_back
20 #define mp make_pair
21 #define all(x) (x).begin(),(x).end()
22 #define fi first
23 #define se second
24 #define SZ(x) ((int)(x).size())
25 typedef vector<int> VI;
26 typedef long long ll;
27 typedef pair<int, int> PII;
28 const ll mod = 1000000007;
29 ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
30 // head
31 const int inf = 0x3f3f3f3f;
32 #define maxn 105
33 char s[maxn][maxn];
34 int n;
35
36 bool sstr(char tms[maxn], int tmpos){
37 bool flag = false;
38
39 for(int k = 0; k < n; k++){
40 if(k == tmpos) continue;
41 int tmslen = strlen(tms), i = 0, j = 0;
42 int tmbslen = strlen(s[k]);
43 bool tmflag = false;
44 for(int i = 0; i < tmbslen; i++){
45 int tmi = i;
46 while(s[k][i] == tms[j] && j < tmslen){
47 i++, j++;
48 }
49 if(j != tmslen){
50 j = 0;
51 i = tmi;
52 }
53 else{
54 tmflag = true;
55 break;
56 }
57 }
58 if(!tmflag)
59 return false;
60 }
61 return true;
62 }
63
64 int main(){
65 int t;
66 scanf("%d", &t);
67 while(t--){
68 memset(s, 0, sizeof(s));
69 scanf("%d", &n);
70 int minlen = inf, mini;
71 for(int i = 0; i < n; i++){
72 scanf("%s", s[i]);
73 int tmlen = strlen(s[i]);
74 if(tmlen < minlen){
75 minlen = tmlen;
76 mini = i;
77 }
78 }
79 int ans = 0, len = minlen;
80 char ss[maxn]; memcpy(ss, s[mini], sizeof(s[mini]));
81
82 for(int i = 0; i < len; i++){
83 for(int j = i; j < len; j++){
84 //temporary string
85 int tmlen = j - i + 1;
86 char tms[maxn];
87 strncpy(tms, ss + i, tmlen);
88 tms[tmlen] = ‘\0‘;
89 if(sstr(tms, mini)){
90 ans = max(ans, tmlen);
91 }
92 //swap the string
93 for(int k = 0; k < (tmlen) / 2; k++){
94 swap(tms[k], tms[tmlen - k - 1]);
95 }
96 if(sstr(tms, mini)){
97 ans = max(ans, tmlen);
98 }
99 }
100 }
101 printf("%d\n", ans);
102 }
103
104 }
题目:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10400 Accepted Submission(s): 4959
标签:tms java mem namespace bre out any stream scan
原文地址:http://www.cnblogs.com/bolderic/p/6868639.html