标签:
hdu1238 暴力搜
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9122 Accepted Submission(s): 4302
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <stack> #include <queue> #include <string> #include <algorithm> const int inf = (1<<31)-1; const int MAXN = 1e2+10; using namespace std; string s[MAXN]; int main() { int t,n,ti,mmin; string ts1,ts2; scanf("%d",&t); while(t--){ scanf("%d",&n); mmin = inf; for(int i=0;i<n;i++){ //scanf("%s",s[i]); cin>>s[i]; if(s[i].length()<mmin){ mmin = s[i].length(); ti = i; } } int mmax = 0,k; /* for(int i=mmin;i>0;i--){ for(int j=0;j<mmin-i+1;j++){ ts1 = s[ti].substr(j,i); //startpos lenth ts2 = ts1; reverse(ts2.begin(),ts2.end()); // cout<<ts1<<" "<<ts2<<endl; for(k=0;k<n;k++){ if(s[k].find(ts1,0)==-1&&s[k].find(ts2,0)==-1) break; } if(k==n&&mmax<ts1.length()) mmax = ts1.length(); } }*/ char ms1[MAXN],ms2[MAXN]; for(int i=0;i<mmin;i++){ for(int j=i;j<mmin;j++){ int b = 0; for(int w=i;w<=j;w++){ ms1[b] = s[ti][w]; ms2[b] = s[ti][j-b]; b++; } //cout<<ms1<<" "<<ms2<<endl; ms1[b] = ms2[b] = ‘\0‘; //printf("%s %s\n",ms1,ms2); for(k=0;k<n;k++){ if(s[k].find(ms1,0)==-1&&s[k].find(ms2,0)==-1){ break; } } if(k==n&&mmax<b) mmax = b; } } cout<<mmax<<endl; } //cout << "Hello world!" << endl; return 0; } /* 3 123 23333 12222 */
标签:
原文地址:http://www.cnblogs.com/EdsonLin/p/5427554.html