http://poj.org/problem?id=3630

 

    很无奈的又一次验证了poj数据弱爆的真理!hdoj用STL根本水不过去,一直是TLE,poj则一下水过....

    今天先这样了,明天再用字典树来试一下。

 

 

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std ;

int main(){
    vector<string> v ;
    string s ;
    int n ;
    cin >> n ;
    int i, b ;
    while (cin >> n){
        b = 0 ;
        v.clear() ;
        for (i=0; i<n; i++){
            cin >> s ;
            v.push_back(s) ;
        }
        sort(v.begin(), v.end()) ;
        for (i=0; i<n-1; ++i){
            if (v[i+1].find(v[i]) == 0){
                cout << "NO" << endl ;
                b=1 ;   break ;
            }
        }
        if(b==0)    cout << "YES" << endl ;
    }
    return 0 ;
}

 

posted on 2011-10-11 23:40  追逐.  阅读(191)  评论(0编辑  收藏  举报