PAT甲级——A1056 Mice and 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. 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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int Np, Ng, w[], res[];
int main()
{
cin >> Np >> Ng;
for (int i = ; i < Np; ++i)
cin >> w[i];
queue<int>q;
for (int i = ; i < Np; ++i)
{
int a;
cin >> a;
q.push(a);
}
while (q.size() > )//即在产生冠军前需要继续迭代
{
int group = q.size() / Ng + (q.size() % Ng == ? : );
int size = q.size();
for (int i = ; i <= group; ++i)
{
int lastN = i == group ? (size - (group - )*Ng) : Ng;//每组队员数量
int index = q.front();
for (int j = ; j < lastN; ++j)
{
res[q.front()] = group + ;//loser的排名为分组数量 + 1
index = w[index] > w[q.front()] ? index : q.front();
q.pop();
}
q.push(index);//存下小组冠军的序号
}
}
res[q.front()] = ;//产生冠军
for (int i = ; i < Np; ++i)
cout << res[i] << (i == Np - ? "" : " ");
return ;
}
PAT甲级——A1056 Mice and Rice的更多相关文章
- pat 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- 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 ...
- A1056. Mice and Rice
Mice and Rice is the name of a programming contest in which each programmer must write a piece of co ...
- 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 ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- PAT 1056 Mice and Rice[难][不理解]
1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...
- PAT甲级1056Mice and Rice
目录 题目介绍 题解 解题思路 代码 参考链接 题目介绍 题目链接 https://pintia.cn/problem-sets/994805342720868352/problems/9948054 ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级题分类汇编——排序
本文为PAT甲级分类汇编系列文章. 排序题,就是以排序算法为主的题.纯排序,用 std::sort 就能解决的那种,20分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...
随机推荐
- clientHeight / scrollHeight / offsetHeight 等属性的区别图
网页(内容)可见区域宽:document.body.clientWidth 网页(内容)可见区域高:document.body.clientHeight 即页面浏览器中可以看到内容的这个区域的高度,一 ...
- MongoDB后台运行
文章目录 命令方式(推荐) 命令行和配置文件方式 命令行: 配置文件: 命令方式(推荐) 如果想在后台运行,启动时只需添加 --fork函数即可. fork: 以守护进程的方式运行MongoDB. 指 ...
- Spring源码由浅入深系列一 简介
概述: Spring是一个企业级的开源框架.它提供轻量级的依赖注入.面向切面编程.全方位的整合框架.下图是Spring框架的组成部分,各部分内容作了简单说明. 依赖注入: 依赖注入是S ...
- MME、PGW、SGW和PCRF的介绍
1.简介原文连接:https://blog.csdn.net/Rong_Toa/article/details/94983607 用户面和控制面板分离2.什么是HSS?HSS有什么主要功能?HSS与H ...
- Java学习之程序运行机制
Java的运行机制是:先编译,后解释. 典型的编译型编程语言是:C和C++. eg:用c语言编写的*.c文件编译生成*.h文件,通过链接将*.h文件链接成*.exe文件,然后就可以运行,编译型的高级语 ...
- 【CF900D】Unusual Sequences
题目 智力下降严重 显然要反演了呀 首先必须满足\(x|y\),否则答案是\(0\) 我们枚举这个数列的\(gcd\)是\(d\)或者\(d\)的倍数 于是答案就是 \[\sum_{x|d}[d|y] ...
- 获取url指定参数值(js/vue)
function getParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&am ...
- java_static关键字
/** * static关键字:静态关键字 * 静态优先于非静态加载到内存中(静态优先于对进入到内存中) * 被static修饰的成员变量不能被序列化的,序列化的都是对象 * transient关键字 ...
- 阿里巴巴飞天大数据架构体系与Hadoop生态系统
很多人问阿里的飞天大数据平台.云梯2.MaxCompute.实时计算到底是什么,和自建Hadoop平台有什么区别. 先说Hadoop 什么是Hadoop? Hadoop是一个开源.高可靠.可扩展的分布 ...
- windows环境下,svn未备份情况下重新恢复
公司有个同事在未打招呼的情况下把公司服务器进行重新装系统,崩溃啊.SVN之前未备份,还好SVN的库(Repositories)还在,如下图: 恢复办法如下: 由于之前安装的就是VisualSVN-Se ...