1056 Mice and Rice(25 分)

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​​ (≤1000), 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​​ (i=0,⋯,N​P​​−1) 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,⋯,N​P​​−1 (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

题目大意:

//看了一遍题意,愣是没看懂。看了三遍还是没看懂,放弃了。看了题解上说的题意,还不不太明白,算了吧,看代码吧。

代码来自: https://www.liuchuo.net/archives/2936

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
struct node {
int weight, index, rank, index0;
};
bool cmp1(node a, node b) {
return a.index0 < b.index0;
}
int main() {
int n, g, num;
scanf("%d%d", &n, &g);
vector<int> v(n);
vector<node> w(n);
for(int i = ; i < n; i++)
scanf("%d", &v[i]);
for(int i = ; i < n; i++) {
scanf("%d", &num);
w[i].weight = v[num];//这个存的是体重
w[i].index = i;//这个存的是第几个,这个是对应老鼠编号的。
w[i].index0 = num;//这个存的是初始顺序。
}
queue<node> q;
for(int i = ; i < n; i++)
q.push(w[i]);
while(!q.empty()) {//目的是找出最胖的。
int size = q.size();
if(size == ) {
node temp = q.front();
w[temp.index].rank = ;
break;
}
int group = size / g;
if(size % g != )//这样来安排最后鼠数几个不够g的。
group += ;
node maxnode;
int maxn = -, cnt = ;
for(int i = ; i < size; i++) {
node temp = q.front();
w[temp.index].rank = group + ;
q.pop();
cnt++;
if(temp.weight > maxn) {
maxn = temp.weight;
maxnode = temp;
}
if(cnt == g || i == size - ) {
cnt = ;
maxn = -;
q.push(maxnode);
}
}
}
sort(w.begin(), w.end(), cmp1);
for(int i = ; i < n; i++) {
if(i != ) printf(" ");
printf("%d", w[i].rank);
}
return ;
}

//还是不太懂什么意思,以后再说。

PAT 1056 Mice and Rice[难][不理解]的更多相关文章

  1. PAT 1056 Mice and Rice

    #include <cstdio> #include <climits> #include <cstdlib> #include <vector> #i ...

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

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

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

  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. 1056. Mice and Rice (25)

    时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...

  6. 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 pie ...

  7. PAT甲题题解-1056. Mice and Rice (25)-模拟题

    有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...

  8. PAT (Advanced Level) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  9. 【PAT甲级】1056 Mice and Rice (25 分)

    题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...

随机推荐

  1. tiny6410SDK制作NFS文件系统

    1.初次编译内核出现问题 解决方法:将uboot的tools目录 下的mkimage拷贝到/bin/下. 2.开机后终端出现mmc0: error -110 whilst initialising S ...

  2. IOS -执行时 (消息传递 )

    一 函数调用概述      Objective-C不支持多重继承(同Java和Smalltalk),而C++语言支持多重继承. Objective-C是动态绑定,它的类库比C++要easy操作. Ob ...

  3. POJ 2229 Sumsets(技巧题, 背包变形)

    discuss 看到有人讲完全背包可以过, 假如我自己做的话, 也只能想到完全背包了 思路: 1. 当 n 为奇数时, f[n] = f[n-1], 因为只需在所有的序列前添加一个 1 即可, 所有的 ...

  4. css揭秘读书笔记

    currentColor属性让hr和段落相同的颜色: div { color: red; } hr { background: currentColor; /* 一定要设置高度*/ height: 0 ...

  5. python常用内置模块,执行系统命令的模块

    Subprocess模块 python3.5将使用Subprocess模块跟操作系统进行交互,比如系统命令,他将替换 os.system os.spawn* subprocess.run()方法封装的 ...

  6. 微信小程序实现文字跑马灯

    wxml: <view>1 显示完后再显示</view> <view class="example"> <view class=" ...

  7. php学习九:存取器&魔术方法

    当声明属性的时候用到了private,那么的话只能本类中才能访问此属性,其他地方无法使用,这个时候需要给外界提供一些方法来使外界访问 方法一:存取器: 可以提供一个public的方法来使外界对类里面的 ...

  8. java基础---->java中Properties的使用

    Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支 持的配置文件,配置文件中很多变量是经常改变的,这样做也 ...

  9. Docker源码分析(四):Docker Daemon之NewDaemon实现

    1. 前言 Docker的生态系统日趋完善,开发者群体也在日趋庞大,这让业界对Docker持续抱有极其乐观的态度.如今,对于广大开发者而言,使用Docker这项技术已然不是门槛,享受Docker带来的 ...

  10. 【BZOJ4429】[Nwerc2015] Elementary Math小学数学 最大流

    [BZOJ4429][Nwerc2015] Elementary Math小学数学 Description Ellen给她的学生教小学数学.期末考试已经来临了.考试有n个题目,每一个题目学生们都要对一 ...