1169 The Judger + set + 模拟
题目链接:https://pintia.cn/problem-sets/994805342720868352/exam/problems/1621700048826490880
题解代码:
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int a, b, n, m;
set<int> s;
vector<vector<int> > res;
bool is_legal(int num) {
if (s.find(num) != s.end()) return false;
for (auto x : s) {
if (s.find(num + x) != s.end()) return true;
}
return false;
}
int main() {
cin >> a >> b >> n >> m;
s.insert(a);
s.insert(b);
set<int> people;
for (int i = 0; i < n; i++) {
vector<int> v(m);
for (int j = 0; j < m; j++) cin >> v[j];
res.push_back(v);
people.insert(i + 1);
}
for (int i = 1; i <= m; i++) {
set<int> not_legal;
for (auto x : people) {
int num = res[x - 1][i - 1];
int flag = 0;
if (!is_legal(num)) {
not_legal.insert(x);
printf("Round #%d: %d is out.\n", i, x);
flag = 1;
}
if (!flag) s.insert(num);
}
for (auto x : not_legal) {
people.erase(x);
}
}
if (people.size()) {
cout << "Winner(s):";
for (auto x : people) {
cout << " " << x;
}
cout << endl;
} else {
cout << "No winner.\n";
}
return 0;
}

浙公网安备 33010602011771号