Codeforces Round #451 (Div. 2) C

来源:互联网 发布:网络维护培训 编辑:程序博客网 时间:2024/05/29 09:21

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


#include<iostream>#include<algorithm>#include<iomanip>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<set>#include<queue>#include<stack>#include<map>#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<string,  vector<string> > mp;set<string> 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<string>::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;}


原创粉丝点击