当前位置: 首页 > 工具软件 > judger > 使用案例 >

7-2 The Judger (25分)

呼延才
2023-12-01

在这里插入代码片集合题。删减了一些内容,每提交,可能通不过编译


#include <iostream>
#include <unordered_set>
#include <vector>
#include <algorithm>
using namespace std;
const int SIZE = 10005;

int N, M;
int adj[SIZE][SIZE];

bool cmp(const int& a, const int& b) {
    return a < b;
}

int main() {
    unordered_set<int> st;
    
    int num1, num2;
    scanf("%d %d", &num1, &num2);
    st.insert(num1);
    st.insert(num2);
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i ++) {
        for (int j = 1; j <= M; j ++) {
            scanf("%d", &adj[i][j]);
        }
    }
    unordered_set<int> error;
    unordered_set<int> winner;

    for (int i = 1; i <= N; i ++)   winner.insert(i);
        
    for (int i = 1; i <= M; i ++) {         //第i轮
        for (int j = 1; j <= N; j ++) {      //第j名选手

            if (error.count(j))     continue;       //出局选手不能再给予判断
            if (st.count(adj[j][i])) {              //第j个人第i轮输入的数已经存在
                error.insert(j);
                winner.erase(j);
                printf("Round #%d: %d is out.\n", i, j);

            } else {
                bool flag = false;
                for (auto x : st) {
                    if (st.count(adj[j][i] + x)) {
                        flag = true;
                        break;
                    }
                }
                if (flag)   {
                    st.insert(adj[j][i]);
                }
                if (!flag) {
                    error.insert(j);
                    winner.erase(j);
                    printf("Round #%d: %d is out.\n", i, j);

                }
            }
        }

    }
    
    
    vector<int> res;
    if (winner.size() != 0) {
        printf("Winner(s): ");
        for (auto x : winner) {
            res.push_back(x);
        }
        sort(res.begin(), res.end(), cmp);
        for (int i = 0; i < res.size(); i ++) {
            if (i != res.size() - 1)    printf("%d ", res[i]);
            else printf("%d\n", res[i]);
        }
    } else {
        printf("No winner.\n");
    }
    
    return 0;
}
 类似资料: