hdu1238水题
2012-07-31 01:47
302 查看
按题目描述的数据量,暴力是不可能过的,居然过了,太假了。。。
/* * hdu1238/win.cpp * Created on: 2012-7-31 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; const int MAXN = 105; char str[MAXN][MAXN]; int minindex, N; bool judge(const char *s) { char s2[MAXN]; int length = strlen(s); for(int i = 0; i < length; i++) { s2[i] = s[length - i - 1]; } s2[length] = 0; for(int i = 0; i < N; i++) { if(i == minindex) { continue; } if(strstr(str[i], s) == NULL && strstr(str[i], s2) == NULL) { return false; } } return true; } int work() { int len = strlen(str[minindex]); for(int i = len; i > 0; i--) { for(int s = 0; s <= len - i; s++) { string temp(&str[minindex][s], i); if(judge(temp.c_str())) { return i; } } } return 0; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif int T; scanf("%d", &T); while(T--) { scanf("%d", &N); int minlen = -1; for(int i = 0; i < N; i++) { scanf("%s", str[i]); int temp = strlen(str[i]); if(temp > minlen) { minlen = temp; minindex = i; } } int ans = work(); printf("%d\n", ans); } return 0; }
相关文章推荐
- hdu 5078 Osu!(水题)
- HDU 2199 Can you solve this equation(二分水题)
- HDU 2094 产生冠军 hash 水题
- hdu 2512 一卡通大冒险 (水题)
- hdu 5053(水题)
- HDU 水题 密码问题
- HDU 1269 迷宫城堡 Tarjan算法水题之神奇建图
- HDU 6095 Rikka with Competition【阅读题】【水题】
- HDU 1029 某个数出现的次数大于等于(N+1)/2的是哪个 map水题
- HDU1985 Conversions【水题】
- HDU-Oil Deposits (DFS,BFS,水题)
- HDU1219 AC Me【输入输出+水题】
- hdu 2565 HDU 1256 水题给的反思 又中招了
- HDU 1024 Max Sum Plus Plus (DP,水题)
- hdu 4802 GPA 水题
- HDU 1029 Ignatius and the Princess IV --- 水题
- hdu 1238
- HDU-5938-Four Operations(杭州CCPC F题)-水题
- hdu 5982(16青岛现场赛)Relic Discovery水题
- hdu1392(一道凸包水题)