zoukankan      html  css  js  c++  java
  • hdu1238水题

    按题目描述的数据量,暴力是不可能过的,居然过了,太假了。。。

    /*
     * 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;
    }
  • 相关阅读:
    构造函数详解
    左值和左值引用、右值和右值引用
    Lambda函数
    std::thread详解
    运算符重载
    友元函数和友元类
    xadmin list_filter 外键数据不显示
    中缀表达式转后缀表达式
    Centos 7 minimal 联网
    python 运用三目判断对象中多个属性 有且非空
  • 原文地址:https://www.cnblogs.com/moonbay/p/2616167.html
Copyright © 2011-2022 走看看