当前位置:网站首页>1056 Mice and Rice
1056 Mice and Rice
2022-07-20 23:14:00 【Brosto_Cloud】
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 (≤1000), 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 (i=0,⋯,NP−1) 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,⋯,NP−1 (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 <algorithm>
#include <queue>
using namespace std;
int p, g, a[1010], b[1010], x;
queue<int>q, q1;
int main() {
cin >> p >> g;
for (int i = 0; i < p; i++) {
cin >> a[i];
}
for (int i = 0; i < p; i++) {
cin >> x;
q.push(x);
}
while (true) {
int group;
if (q.size() % g == 0) {
group = q.size() / g;
} else {
group = q.size() / g + 1;
}
while (!q.empty()) {
int maxx = -1, ind = -1;
for (int i = 0; i < g; i++) {
if (!q.empty()) {
int t = q.front();
q.pop();
b[t] = group + 1;
if (a[t] > maxx) {
maxx = a[t];
ind = t;
}
}
}
q1.push(ind);
}
if (q1.size() == 1) {
b[q1.front()] = 1;
break;
} else {
q = q1;
queue<int>empty;
swap(empty, q1);
}
}
for (int i = 0; i < p; i++) {
cout << b[i];
if (i != p - 1) {
cout << ' ';
}
}
return 0;
}
边栏推荐
- [pictures and texts] this article explains the JVM architecture, class file structure and bytecode structure!!
- 远程控制软件也要有plan B备选方案
- 卷积神经网络单图超分辨率的深度学习方法
- 超简单的三管无感无刷三相电机驱动板
- 【图文并茂】这次一文讲透JVM架构、类文件结构、字节码结构!!
- The performance of major mainstream programming languages is PK, and the results are unexpected
- Deep learning method of convolutional neural network single image super-resolution
- Four redis cluster schemes and their advantages and disadvantages
- 进程的五种状态
- tars源码分析之21
猜你喜欢
The remote control software should also have plan B alternatives
三级调度之间的联系及区别
华为无线设备配置不同业务VLAN的AP间非快速漫游
It seems to be a bug of thread pool, but I think the source code design is unreasonable.
进程控制块(PCB) 包含哪些信息
Four redis cluster schemes and their advantages and disadvantages
思科配置单臂路由的实际案例,很简单
[pictures and texts] this article explains the JVM architecture, class file structure and bytecode structure!!
第03篇:SQL语法树解析
工作经验总结1
随机推荐
Analysis of tars source code 25
JS operators and expressions \ flow structure of functions and programs
Huawei wireless devices are configured with ACL based message filtering
ONEFLOW V0.8.0 officially released
Kubernetes service load balancing implementation mechanism
华为无线设备配置同一业务VLAN的AP间快速漫游
星巴克CEO称可能关闭更多店面以保证员工安全
Outofmemoryerror troubleshooting of memory overflow
静态通讯录的实现
Work experience summary 1
Weekly recommended short videos: does the development of the Internet of things pose a greater challenge?
复杂链表的复制
每周推荐短视频:物联网开发提出更大挑战?
我用Redis分布式锁,抢了瓶茅台,然后GG了~~
卷积神经网络单图超分辨率的深度学习方法
有了线程后,发生的变化
最新微服务组件选型
How to transfer files on the server_ By customized hierarchical relationship_ Compress and download
My SQL is OK. Why is it still so slow? MySQL locking rules
如何将服务器上的文件_按自定义的层级关系_进行压缩并下载