PAT 20春 7-2 The Judger (25分)

10 篇文章 0 订阅
这篇博客介绍了一个数字游戏的规则和一个编程竞赛的任务,玩家需要给出之前给出的两个正整数的差值,不能重复。博主分享了输入输出规格、样例,并反思了因英语理解障碍和紧张导致的错误,最终通过调整数据结构解决了超时问题。
摘要由CSDN通过智能技术生成

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 [1,10​5​​].

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

Then N lines follow, each contains M positive integers. The i-th line corresponds to the i-th player (i=1,⋯,N). 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.

difference - 差值

我想我以后都忘不了这单词还有这个意思

反思一下,英语太烂读不懂题面,但其实从第一个样例的前几个数是可以反猜题意的

还是心态问题,一紧张心态就爆炸了,完全失去了正常思考的能力 

如果读懂题目后就比较简单了,不过会有一个点超时。最开始我用的unorder_map,改成数组和vector才过了

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reo(i,a,n) for(int i=a;i<=n;i++)
#define ll long long
using namespace std;
const int N=1e3+233;
int n,m;
int a[N][N];
int s[100010];
vector<int>v;
int flag[N];
int vis[100010];
int main(){
    int n1,n2;
    cin>>n1>>n2;
    s[abs(n1-n2)]=1;
    v.push_back(n1);
    v.push_back(n2);
    vis[n1]=1;
    vis[n2]=1;
    cin>>n>>m;
    rep(i,0,n){
        rep(j,0,m) cin>>a[i][j];
    }
    rep(i,0,m){
        rep(j,0,n){
            if(flag[j]) continue;
            int num=a[j][i];
            if(!s[num]||vis[num]){
                printf("Round #%d: %d is out.\n",i+1,j+1);
                flag[j]=1;
            }
            else{
                for(auto p:v){
                    s[abs(p-num)]=1;
                }
                v.push_back(num);
                vis[num]=1;
            }
        }
    }
    vector<int>ans;
    rep(i,0,n){

        if(!flag[i]){
           ans.push_back(i);
        }
    }
    if(ans.size()){
        cout<<"Winner(s):";
        for(int j=0;j<ans.size();j++)
            printf(" %d",ans[j]+1);
        cout<<endl;
    }
    else puts("No winner.");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值