title: PTA 1056 Mice and Rice (25分) date: 2020-10-02 15:43:59 tags:
队列queue categories:[刷题,PAT]本文由参考于柳神博客写成
柳神的博客,这个可以搜索文章
柳神的个人博客,这个没有广告,但是不能搜索
还有就是非常非常有用的算法笔记
PS 今天也要加油鸭
Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse.
First the playing order is randomly decided for N**P programmers. Then every N**G programmers are grouped in a match. The fattest mouse in a group wins and enters the next turn. All the losers in this turn are ranked the same. Every N**G winners are then grouped in the next match until a final winner is determined.
For the sake of simplicity, assume that the weight of each mouse is fixed once the programmer submits his/her code. Given the weights of all the mice and the initial playing order, you are supposed to output the ranks for the programmers.
Each input file contains one test case. For each case, the first line contains 2 positive integers: N**P and N**G (≤1000), the number of programmers and the maximum number of mice in a group, respectively. If there are less than N**G mice at the end of the player’s list, then all the mice left will be put into the last group. The second line contains N**P distinct non-negative numbers W**i (i=0,⋯,N**P−1) where each W**i is the weight of the i-th mouse respectively. The third line gives the initial playing order which is a permutation of 0,⋯,N**P−1 (assume that the programmers are numbered from 0 to N**P−1). All the numbers in a line are separated by a space.
For each test case, print the final ranks in a line. The i-th number is the rank of the i-th programmer, and all the numbers must be separated by a space, with no extra space at the end of the line.
PS:这题我是真的没有看懂,一脸懵逼,就是那种:词我好像都认识,但是连在一起就是不会.
Mice 老鼠
Rice 米饭
Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map.
“老鼠和大米”是一个编程竞赛的名称,在这个竞赛中,每个程序员必须编写一段代码来控制给定地图中鼠标的移动。
sake of 为了
For the sake of simplicity, assume that the weight of each mouse is fixed once the programmer submits his/her code. Given the weights of all the mice and the initial playing order, you are supposed to output the ranks for the programmers.
意译:
为了简化流程,我们让每个老鼠的重量一开始都是固定好的.老鼠的一开始的顺序也是给定的.你最后要输出程序的结果.
给了你Np只老鼠,还有他们的重量.
然后再给你,他们的初始顺序.
6 0 8 7 10 5 9 1 4 2 3就是代表着 19 25 57 22 10 3 56 18 37 0 46 这个重量顺序然后要你输出这个顺序下的,老鼠的排名
这个思路是我copy算法笔记的.我自己是想不出来这么好的算法的.
① 开一个结构体mouse用来记录每只老鼠的质量和排名
② 定义一个队列,用来再算法过程中按顺序处理每轮的老鼠
算出下面的几个数据.
每轮比赛把老鼠分成的组数group,设当前轮的参赛老鼠有temp只.如果temp%Ng为0 ,就代表可以整除.group就是temp/Ng 不然的话,group还有加一 .
因为题目讲到了.剩下来的老鼠自己成为一组.
③ 因为每组晋级一只老鼠.所以,每轮晋级的老鼠数量都是group.
没有晋级的老鼠排名都是group+1 —题目讲到了,没有晋级的老鼠排名相同
如果这篇文章对你有张帮助的话,可以用你高贵的小手给我点一个免费的赞吗
相信我,你也能变成光.
如果你有任何建议,或者是发现了我的错误,欢迎评论留言指出.