首页 > 其他 > 详细

POJ1129(贪心)

时间:2019-04-08 20:13:09      阅读:212      评论:0      收藏:0      [点我收藏+]

笔者休息娱乐。贪心即可,爱怎么暴力怎么暴力。莽WA,改了几下算法发现是输出中二了……

int T, color[26], tot;
bool adj[26][26];
string s;

void get(int cur) {
    set<int> s;
    rep(i, 0, T - 1)
        if (adj[cur][i] && color[i])
            s.insert(color[i]);
    
    rep(i, 1, 26)
        if (s.find(i) == s.end()) {
            color[cur] = i;
            return;
        }
}

int main() {
    while (cin >> T && T) {
        init(adj, 0);
        init(color, 0);
        tot = 0;

        rep(i, 1, T) {
            cin >> s;
            int a = s[0] - 'A';
            rep(j, 2, s.length() - 1) {
                int b = s[j] - 'A';
                adj[a][b] = 1;
            }
        }
        
        rep(i, 0, T - 1) {
            get(i);
            tot = max(tot, color[i]);
        }
        cout << tot << " channel" << (tot > 1 ? "s" : "") << " needed.\n";
    }
    return 0;
}

POJ1129(贪心)

原文:https://www.cnblogs.com/AlphaWA/p/10672960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!