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分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...
随机推荐
- 更改网卡名称以及重启网卡提示Determining if ip address x.x.x.x is already in use for device eth0
安装系统完成后,在CentOS6.6下网卡名称变为em1,有些不太方便,还是改回eth0 修改grub配置文件,vi /boot/grub/grub.conf,增加如下红色字体 kernel /vml ...
- 求一个n!中尾数有多少个零
题目描述: 输入一个正整数n,求n!(即阶乘)末尾有多少个0? 比如: n = 10; n! = 3628800,所以答案为2 输入描述: 输入为一行,n(1 ≤ n ≤ 1000) 输出描述: 输出 ...
- mysql用户和权限
1.创建用户 格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码" mysql>grant all privileges o ...
- SpringAOP中的aop:config标签
我们使用Spring的AOP功能的时候发现,我们使用普通的配置方式的时候,我们无法精确的确定将切面类中的哪个方法切入到哪个切入点上, 所以我们可以使用aop的专用标签来完成相关的配置.其中主要表现是使 ...
- NEERC 1999 Divisibility /// 同余DP oj22640
题目大意: 输入n,m: ( 1 ≤ N ≤ 10000, 2 ≤ M ≤ 100 ) 接下来n个数:Each integer is not greater than 10000 by it's ab ...
- springcloud Eureka Finchley.RELEASE 版本
创建一个父项目cloud-demo pom.xml <?xml version="1.0" encoding="UTF-8"?> <proje ...
- 跟我一起使用socket.io创建聊天应用
安装express插件 新建index.js var app = require('express')(); var http = require('http').Server(app); app.g ...
- 廖雪峰Java13网络编程-1Socket编程-1网络编程概念
1.计算机网络 1.1 什么是计算机网络? 两台或更多计算机组成的网络 同一网络内的任意2台计算机都可以直接通信 所有计算机必须遵循同一种网络协议 1.2 什么是互联网 互联网是网络的网络 互联网采用 ...
- TSP+期望——lightoj1287记忆化搜索,好题!
感觉是很经典的题 记忆化时因为不好直接通过E判断某个状态是否已经求过,所以再加一个vis打标记即可 /*E[S][u]表示从u出发当前状态是S的期望*/ #include<bits/stdc++ ...
- ssoj 2279 磁力阵
说不想改最后还是向T1屈服了..然后就de了一下午Bug... 虽然昨天随口扯的有点道理,正解就是迭代加深A星搜索,但实际写起来就十分难受了. 说自己的做法,略鬼畜. 每个正方形的边界上的边.每条边在 ...