原题链接:暂无
关键词:模拟、unordered_set

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.

题目大意:
裁判先给出两个数,后面是n个玩家在m轮游戏中给出的数。如果玩家给出的数和之前的数重复,或者不是之前数的差值,则该玩家淘汰。淘汰之后的回合该玩家给出的数忽略。

分析:
考试的时候我都没读懂样例,只是单纯的以为要满足给的数在最早两个数的区间内且不能重复。而he difference of two numbers 的意思是两数之差,这波是英语水平的问题,考试的时候一定要根据样例来判断规则……

用二维数组存储玩家给出的所有数,用unordered_set存储合法的数。首先判断玩家是否已经淘汰,若已经淘汰应当continue到下一个数。然后判断该数是否在set中,后面的部分就没有难度了。

要用unordered_set防止出现超时的问题。

代码:

#include <bits/stdc++.h>
using namespace std;int a, b, n, m;
int g[15][105];
unordered_set<int> se;
vector<bool> alive;bool judge(int x){ //是否是之前数的差值 unordered_set<int>::iterator it;for(it = se.begin(); it != se.end(); it++){if(se.find((*it) + x) != se.end()) return true;}return false;
}int main(){//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);cin >> a >> b >> n >> m;se.insert(a);se.insert(b);alive.resize(n+1);for(int i = 1; i <= n+1; i++) alive[i] = 1;for(int i = 1; i <= n; i ++){for(int j = 1; j <= m; j ++){scanf("%d", &g[i][j]);}}for(int j = 1; j <= m; j ++){for(int i = 1; i <= n; i ++){if(!alive[i]) continue;int temp = g[i][j];if(se.find(temp) != se.end() || !judge(temp)){alive[i] = 0;printf("Round #%d: %d is out.\n", j, i);}else se.insert(temp);}}vector<int> winner;for(int i = 1; i <= n; i ++){if(alive[i]) winner.push_back(i);}if(winner.size() == 0) puts("No winner.");else{printf("Winner(s):");for(int i = 0; i < winner.size(); i ++)printf(" %d", winner[i]);}return 0;
}

2020.7.25 PAT甲级7-2 The Judger (25分)相关推荐

  1. PAT甲级1009 Product of Polynomials (25分)

    PAT甲级1009 Product of Polynomials (25分) 题目: 题目分析:和之前有一道多项式相加很像,注意点是不仅仅数组系数会变,还可能会出现之前没有的指数,因此要开2001大小 ...

  2. PAT甲级1076 Forwards on Weibo (30 分) :[C++题解]图论、bfs

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: BFS如何搜前k层?统计前k层的点数. ac代码 #include<bits/stdc++.h> using names ...

  3. PAT甲级1068 Find More Coins (30 分):[C++题解]DP、背包问题、dp输出方案

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:m是背包容量,a1,a2,....,ana_1,a_2,....,a_na1​,a2​,....,an​是n个物品,第i个物品的体积是 ...

  4. PAT甲级1045 Favorite Color Stripe (30 分):[C++题解]最佳彩色带、DP、公共子序列变形

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:这是一个公共子序列的问题.但是有点变式,序列a和序列b不是完全等价的,序列a的每个元素可以对应多个相同元素,而且有些元素可以不使用.比 ...

  5. PAT甲级1119 Pre- and Post-order Traversals (30分):[C++题解]暴搜dfs、前序遍历和后序遍历求中序遍历

    文章目录 题目分析 题目链接 题目分析 分析 给了前序遍历和后序遍历,能够确定根结点,但是左子树和右子树的长度是不确定的.这里采用的解决方案是枚举左子树的结点个数,其实右子树的结点个数也确定了.对于每 ...

  6. PAT甲级1143 Lowest Common Ancestor (30 分):[C++题解]LCA、最低公共祖先

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:二叉搜索树的中序遍历是隐含给定的,它的中序遍历就是从小到大排列. 所以这道题先是根据给定的前序遍历和中序遍历,建树. 建树的时候需要用 ...

  7. 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

    题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...

  8. PAT甲级-1045 Favorite Color Stripe (30分)

    点击链接PAT甲级-AC全解汇总 题目: Eva is trying to make her own color stripe out of a given one. She would like t ...

  9. 2020/7/25 pat甲级45分总结

    额,第一次考甲级,慌慌的,第一题第三题都比较简单,就都写得很快,然后第二题就死磕了..题目中的difference一直当成"差异"来理解,然后一直想不出测试用例的答案是咋的出来的. ...

  10. 1020. Tree Traversals (25) PAT甲级真题

    之前我看了这道题,实在是看不懂网上的解题答案,他们的具体思路基本上就是通过后续遍历和中序遍历,直接推出层次遍历. 我苦思冥想了半天,是在没看懂这种思路,于是想了一个笨点的但是也比较好理解的思路,通过后 ...

最新文章

  1. 不拆分单词也可以做NLP,哈工大最新模型在多项任务中打败BERT,还能直接训练中文...
  2. mybatis3.2.8 与 hibernate4.3.6 混用
  3. 编程学习记录12:Oracle数据库的一些基本操作2,表相关操作,添加约束
  4. C 语言 普通基本数据类型 以及 其储存形式
  5. 双清模式无命令_linux性能监控:IO性能监控命令之iotop命令
  6. 这两天说到的苹果软件中毒是个什么情况?
  7. 如何在10亿个数中找到前1000大的数?
  8. CentOS 7笔记yum install epel-release
  9. iconfont-矢量图标字体的运用
  10. html中offsetTop、clientTop、scrollTop、offsetTop
  11. 中国邮政国际挂号信网上查询
  12. autofs后 卸载_nfs挂载无法卸载
  13. HDU5832(大数取模-秦九昭算法)
  14. AllData一站式大数据平台【一】
  15. Chapter4.3:根轨迹法
  16. 树莓派3b连接GPS+BD模块并用python获取数据(串口版)
  17. 【NI Multisim 14.0原理图设计基础——元器件分类】
  18. ROS IOError: [Errno 13] Permission denied 报错
  19. No result defined for action com.frank.action.RegistAction and result success
  20. 变革中的思索之重读《孙子兵法》

热门文章

  1. linux文件怎么打包压缩文件,linux文件怎么打包、压缩和解压?详细教程来了!...
  2. 香港拼音--汉字对照表
  3. 3个方法实现微信多开登陆 适用电脑端(WIN7/WIN10)
  4. Mysql表和数据的复制操作
  5. 2079 ACM 选课时间 背包 或 母函数
  6. 【Keil变量定义】定义extern类型变量
  7. li标签中,img居中显示
  8. PDM与ERP系统集成设计
  9. C语言工程网络图,三分钟教你学会 双代号网络图的绘制
  10. 电脑间通过串口传输数据【串口练习】