Codeforces Round #451 (Div. 2) C - Phone Numbers 暴力

每个姓名的电话号码 暴力枚举


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
#define kuaidian ios::sync_with_stdio(0);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2e5 + 7, maxd = 1e8;
const ll mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;

int T, n;

map > mp;
set name;

bool is_ok(string a, string b) {
    if(a.length() < b.length()) return false;
    int aa = a.length()-1, bb = b.length()-1;
    while(bb >= 0) {
        if(a[aa] != b[bb]) return false;
        aa--; bb--;
    }
    return true;
}

int main() {
    kuaidian;
    cin >> n;
    string s, t;
    int m;
    for(int i = 0; i < n; ++i) {
        cin >> s >> m;
        name.insert(s);
        for(int j = 0; j < m; ++j) {
            cin >> t;
            mp[s].push_back(t);
        }
    }

    set::iterator it;
    int vis[21][1111], cnt = 0;
    memset(vis, 0, sizeof vis);
    for(it = name.begin(); it != name.end(); ++it) {

        for(int i = 0; i < mp[*it].size(); ++i ) {
            for(int j = i+1; j < mp[*it].size(); ++j) {
                if(vis[cnt][i] || vis[cnt][j]) continue;
                if(is_ok(mp[*it][i], mp[*it][j])) {
                    vis[cnt][j] = 1;
                }
                else if(is_ok(mp[*it][j], mp[*it][i])) {
                    vis[cnt][i] = 1;
                }
            }
        }
        cnt++;
    }

    cout << name.size() << endl;

    int pos = 0;
    for( it = name.begin(); it != name.end(); ++it) {
        cout << (*it) << " ";
        int num = 0;
        for(int i = 0; i < mp[*it].size(); ++i) {
            if(vis[pos][i] == 0) num++;
        }
        cout << num;
        for(int i = 0; i < mp[*it].size(); ++i ) {
            if(!vis[pos][i]) {
                cout << " " << mp[*it][i];
            }
        }
    cout << endl;
    pos++;
    }


    return 0;
}








你可能感兴趣的:(codefoces,暴力)