1056 Mice and Rice (25分)队列
1.27刷题2
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 NP programmers. Then every NG 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 NG 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.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: NP and NG (≤), the number of programmers and the maximum number of mice in a group, respectively. If there are less than NG 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 NP distinct non-negative numbers Wi (,) where each Wi is the weight of the i-th mouse respectively. The third line gives the initial playing order which is a permutation of 0 (assume that the programmers are numbered from 0 to NP−1). All the numbers in a line are separated by a space.
Output Specification:
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.
Sample Input:
11 3
25 18 0 46 37 3 19 22 57 56 10
6 0 8 7 10 5 9 1 4 2 3
Sample Output:
5 5 5 2 5 5 5 3 1 3 5
// 25 18 0 46 37 3 19 22 57 56 10
// 6 0 8 7 10 5 9 1 4 2 3 //题没看懂,其次要不是这个小结是队列,我根本想不起来用这个
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
queue<int> q;
// int maxabc(int a,int b,int c){ //题目给的ng是3,我就鬼迷心窍写个这。。
// int max=-1;
// max=a>b?a:b;
// max=max>c?max:c;
// return max;
// }
struct mouse {//不用结构体多麻烦呀,为啥不用呀
int weight,record;
} mice[maxn];
int main() {
int np,ng,b;
cin>>np>>ng; for(int i=0; i<np; i++)cin>>mice[i].weight;
for(int i=0; i<np; i++) {
cin>>b;
q.push(b);
}
int temp=np,group;//没想到
while(q.size()!=1) {//这个循环是真的大 ,没想到是分组来排名的,确实还是模拟,就是按照思路写的代码
if(temp%ng==0)group=temp/ng;
else group=temp/ng+1;
for(int i=0; i<group; i++) {
int k=q.front();
for(int j=0; j<ng; j++) {
if(i*ng+j>=temp)break;
int front=q.front();
if(mice[front].weight>mice[k].weight)k=front;
mice[front].record=group+1;//该轮老鼠排名为group+1
q.pop();
}
q.push(k);//优胜者进决赛圈
}
temp=group;//group在缩小
}
mice[q.front()].record=1;
for(int i=0; i<np; i++) {
cout<<mice[i].record;
if(i<np-1)cout<<" ";
}
}
明天还有实习,还有复试,还有毕设,还有过年,还有春晚,还有黑眼圈,还有卷。
1056 Mice and Rice (25分)队列的更多相关文章
- PAT 甲级 1056 Mice and Rice (25 分) (队列,读不懂题,读懂了一遍过)
1056 Mice and Rice (25 分) Mice and Rice is the name of a programming contest in which each program ...
- 【PAT甲级】1056 Mice and Rice (25 分)
题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...
- pat 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- PAT Advanced 1056 Mice and Rice (25) [queue的⽤法]
题目 Mice and Rice is the name of a programming contest in which each programmer must write a piece of ...
- 1056. Mice and Rice (25)
时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...
- PAT甲题题解-1056. Mice and Rice (25)-模拟题
有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...
- PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- pat1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and ...
- PAT 1056 Mice and Rice[难][不理解]
1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...
随机推荐
- acwing 890. 能被整除的数
#include<bits/stdc++.h> #define ll long long using namespace std; int m; int n,p[20]; int sum, ...
- 常见链表操作-链表中环的检测(JAVA实现)
问题如何检测一个单链表中是否有环,例如下图的例子. 解决思路1:快慢指针法这是最常见的方法.思路就是有两个指针P1和P2,同时从头结点开始往下遍历链表中的所有节点. P1是慢指针,一次遍历一个节点.P ...
- java中使用for循环删除List集合的陷阱
一直以为是数据库的数据取错了,导致后面for循环出错.慢慢调试之后,发现这原来是一个坑.回到正题 (错误示范:使用for循环删除list集合) for(int i=0;i<list.size() ...
- XCTF_RE-Crc-300
这题讲道理其实还算简单的,还以为是啥算法呢..吓我一跳..拖入ida之后,发现逻辑还是挺清晰的 这个是关键函数,第一个if就可以求出后10个字符是啥了.. 接下就是对一个列表的赋值,然后就是一个dow ...
- CSP2020游记
初赛 这次考试完全没准备好啊-- Day0 (10.10) 本来打算看看初赛的内容 然后因为各种原因咕了-- 就做了一下洛谷的模拟卷 结果 \(40 \text{min}\) 得 \(80 \text ...
- 备战-Java 并发
备战-Java 并发 谁念西风独自凉,萧萧黄叶闭疏窗 简介:备战-Java 并发. 一.线程的使用 有三种使用线程的方法: 实现 Runnable 接口: 实现 Callable 接口: 继承 Thr ...
- c语言:scanf()高级应用
1) 指定读取长度 还记得在 printf() 中可以指定最小输出宽度吗?就是在格式控制符的中间加上一个数字,例如,%10d表示输出的整数至少占用 10 个字符的位置: 如果整数的宽度不足 10,那么 ...
- 剖析:如何用 SwiftUI 5天组装一个微信 —— 通讯录发现我篇
前置资源 GitHub: SwiftUI-WeChatDemo 第零章:用 SwiftUI 5天组装一个微信 第一章:剖析:如何用 SwiftUI 5天组装一个微信 -- 聊天界面篇 通讯录 通讯录的 ...
- 拿来-util工具函数
记录一些写的好的工具函数.以便学习和项目中直接拿来使用. 判断值是否相等:使用于任何数据类型:基本数据类型和复杂深层次对象 function deepEqual (a, b) { if (a === ...
- Leetcode4. 寻找两个正序数组的中位数
> 简洁易懂讲清原理,讲不清你来打我~ 输入两个递增数组,输出中位数![在这里插入图片描述](https://img-blog.csdnimg.cn/25550994642144228e9862 ...