7-2 The Judger (25 分)

A game of numbers has the following rules: at the beginning, two distinct positive integers are given by the judge. Then each player in turn must give a number to the judge. The number must be the difference of two numbers that are previously given, and must not be duplicated to any of the existed numbers. The game will run for several rounds. The one who gives a duplicate number or even a wrong number will be kicked out.

Your job is to write a judger program to judge the players' numbers and to determine the final winners.

Input Specification:

Each input file contains one test case. For each case, the first line gives two distinct positive integers to begin with. Both numbers are in [.

In the second line, two numbers are given: N (2), the number of players, and M (2), the number of rounds.

Then N lines follow, each contains M positive integers. The i-th line corresponds to the i-th player (,). The game is to start from the 1st player giving his/her 1st number, followed by everybody else giving their 1st numbers in the 1st round; then everyone give their 2nd numbers in the 2nd round, and so on so forth.

Output Specification:

If the i-th player is kicked out in the k-th round, print in a line Round #k: i is out.. The rest of the numbers given by the one who is out of the game will be ignored. If more than one player is out in the same round, print them in increasing order of their indices. When the game is over, print in the last line Winner(s): W1 W2 ... Wn, where W1 ... Wn are the indices of the winners in increasing order. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the beginning or the end of the line. If there is no winner, print No winner. instead.

Sample Input 1:

101 42
4 5
59 34 67 9 7
17 9 8 50 7
25 92 43 26 37
76 51 1 41 40
 

Sample Output 1:

Round #4: 1 is out.
Round #5: 3 is out.
Winner(s): 2 4
 

Sample Input 2:

42 101
4 5
59 34 67 9 7
17 9 18 50 49
25 92 58 1 39
102 32 2 6 41
 

Sample Output 2:

Round #1: 4 is out.
Round #3: 2 is out.
Round #4: 1 is out.
Round #5: 3 is out.
No winner.
 
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
vector<int> v;
vector<int> p[maxn];
bool win[maxn];
bool Judge(int n){
    int len=v.size();
    for(int i=0;i<len;i++){
        if(n==v[i]){
            return false;
        }
    }
    sort(v.begin(),v.end());
 for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(v[i]+n==v[j]){
                return true;
            }
        }
    }

    return false;
    
}
int main(){
    fill(win,win+maxn,true);
    int a,b;
    cin>>a>>b;
    v.push_back(a);
    v.push_back(b);
    int n,m,temp;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>temp;
            p[i].push_back(temp);
        }
    }
    int count=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(win[j]==true&&Judge(p[j][i])){
                v.push_back(p[j][i]);
            }
            else if(win[j]==true){
                printf("Round #%d: %d is out.\n",i+1,j+1);
                win[j]=false;
            }
        }
    }
    bool flag=false;
    bool isPrint=false;
    for(int i=0;i<n;i++){
        if(win[i]==true){
            if(isPrint==false){
                printf("Winner(s):");
                isPrint=true;
            }
            flag=true;
            printf(" %d",i+1);
        }
    }
    if(flag==true){
        printf("\n");
    }
    else{
        printf("No winner.\n");
    }
    return 0;
}

 

posted @ 2021-03-09 22:38  XA科研  阅读(52)  评论(0编辑  收藏  举报