PAT 2. 甲级第2题春季考试
原题链接
中等
作者:
leo123456
,
2020-09-05 10:17:46
,
所有人可见
,
阅读 450
#include <iostream>
#include<cstring>
#include <unordered_set>
#include <vector>
using namespace std;
int main()
{
int fst, sec;
int row, col;
scanf("%d %d", &fst, &sec);
scanf("%d %d", &row, &col);
vector<vector<int>> v(row, vector<int>(col));
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
scanf("%d", &v[i][j]);
}
}
vector<bool> player(row, true);
unordered_set<int> us{ fst, sec };
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
if (!player[j]) continue;
if (us.count(v[j][i]))
{
printf("Round #%d: %d is out.\n", i + 1, j + 1);
player[j] = false;
}
else
{
bool valid=false;
for (auto& x : us)
{
if (us.count(x + v[j][i]))
{
valid = true;
us.insert(v[j][i]);
break;
}
}
if (!valid)
{
printf("Round #%d: %d is out.\n", i + 1, j + 1);
player[j] = false;
}
}
}
}
bool flag=false;
for (int i = 0; i < row; i++)
{
if (player[i])
{
if (!flag)
{
printf("Winner(s):");
flag = true;
}
printf(" %d", i + 1);
}
}
if (!flag) puts("No winner.");
return 0;
}