close

題目大意:  分類,如果跟0號一起上課,居家隔離,跟居家隔離上課,自主隔離

思路:  Set + 暴力法。數字太小,直接暴力。每一行先找出居家,再來每一行如果有跟居家上課且不在居家隔離,放入自主隔離。

代碼:  

#include <bits/stdc++.h>

#define louisfghbvc int t; cin >> t; while(t--)
using namespace std;

void solve(){
    int n, m;
    cin >> n;
    set<int> home, self;
    vector<int> course[n];
    for(int i = 0; i < n; ++i){
        cin >> m;
        course[i] = vector<int>(m);
        bool gg = false;
        for(auto &it: course[i]){
            cin >> it;
            if(!it) gg = 1;
        }
        if(gg){
            for(int x: course[i]) if(x) home.insert(x);
        }
    }
    for(int i = 0; i < n; ++i){
        bool qq = false;
        for(int x: course[i]){
            if(home.count(x)) qq = true;
        }
        if(qq){
            for(int x: course[i]) if(x && !home.count(x)) self.insert(x);
        }
    }
    if(home.empty()) cout << "None\n";
    else{
        bool f = true;
        for(int x : home){
            if(!f) cout << " ";
            cout << x;
            f = false;
        }
        cout << "\n";
    }
    if(self.empty()) cout << "None\n";
    else{
        bool f = true;
        for(int x : self){
            if(!f) cout << " ";
            cout << x;
            f = false;
        }
        cout << "\n";
    }
}

int main()
{
    //louisfghbvc{
        solve();
    //}
    return 0;
}

arrow
arrow
    創作者介紹
    創作者 尾玉 的頭像
    尾玉

    louisfghbvc的部落格

    尾玉 發表在 痞客邦 留言(0) 人氣()