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.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: N​P​​ and N​G​​ (≤), 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​​ (,) 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 (assume that the programmers are numbered from 0 to N​P​​−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的更多相关文章

  1. pat 甲级 1056. Mice and Rice (25)

    1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...

  2. 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 ...

  3. A1056. Mice and Rice

    Mice and Rice is the name of a programming contest in which each programmer must write a piece of co ...

  4. 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 ...

  5. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  6. PAT 1056 Mice and Rice[难][不理解]

    1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...

  7. PAT甲级1056Mice and Rice

    目录 题目介绍 题解 解题思路 代码 参考链接 题目介绍 题目链接 https://pintia.cn/problem-sets/994805342720868352/problems/9948054 ...

  8. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  9. PAT甲级题分类汇编——排序

    本文为PAT甲级分类汇编系列文章. 排序题,就是以排序算法为主的题.纯排序,用 std::sort 就能解决的那种,20分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...

随机推荐

  1. 像bootstrap一样的去做web编程

    1: 闭包 boot的闭包方式有点特别,普通的闭包是这样的: (function ($) { })(jQuery) 这种写法是怕全局污染,把$封闭在自己的空间里,暴露在外面的只有jQuery,这样,如 ...

  2. <每日一题>题目5:生成器表达式面试题

    题目: def demo(): for i in range(4): yield i g = demo() g1 = (i for i in g ) g2 = (i for i in g1) prin ...

  3. [SNOI2017]遗失的答案

    题目 首先\(G,L\)肯定会满足\(G|L\),否则直接全部输出\(0\) 之后我们考虑一下能用到的质因数最多只有\(8\)个 同时我们能选择的数\(x\)肯定是\(L\)的约数,还得是\(G\)的 ...

  4. SQL中的左连接与右连接,内连接有什么不同

    SQL中的左连接与右连接,内连接有什么不同 我们来举个例子.天庭上面有一个管理系统:管理系统有个主表:主表记录着各个神仙的基本信息(我们把它当成表A).还有个表记录着他们这个神仙的详细信息(我们把它当 ...

  5. 1、docker centos 安装

    Docker for CentOS: 第一步:使用官方yum仓库 [root@linux-node1 ~]# yum install -y yum-utils [root@linux-node1 ~] ...

  6. tensorflow识别验证码(1)-tensorflow安装,验证码生成

    什么是TensorFlow?  TensorFlow是Google开发的一款神经网络的Python外部的结构包, 也是一个采用数据流图来进行数值计算的开源软件库.TensorFlow 让我们可以先绘制 ...

  7. Entity Framework Code First 模式-建立一对一联系

    使用的例子为教室(ClassRoom),教室里的多媒体设备(Device),一个教室里有一套多媒体设备,一套多媒体设备只放在一个教室里. 1.Data Annotations方式 需要在任意一方的主键 ...

  8. FileCloud 的原理简述&自己搭建文件云

    FileCloud 的原理简述&自己搭建文件云 copyright(c) by zcy 关于如何使用IIS创建asp服务,请读者自行研究 注:不要忘记添加入站规则 代码的存储: 根目录 fil ...

  9. php实现在不同国家显示网站的不同语言版本

    首先,你的网站本身要拥有多个语言版本.不然的话你就只能用JS去转化了. 1.通过ip去定位,这个要引用到第三方的接口进行数据的完整返回,但是不知道是我的网速太慢还是什么原因,个人觉得这个方法会卡顿: ...

  10. JS 标签页切换(复杂)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...