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. KAFKA安装+配置详解+常用操作+监控

    http://blog.csdn.net/hadas_wang/article/details/50056381 http://qiyishi.blog.51cto.com/5731577/18575 ...

  2. 如何在 React Native 中写一个自定义模块

    https://my.oschina.net/jpushtech/blog/983230

  3. Visual Studio使用技巧,创建自己的代码片段

    1.代码片段的使用示例 在编写代码中常会使用代码片段来提高我们的编写代码的效率,如:在Visual Studio中编写一个 for(int i = 0; i < length;i++) { } ...

  4. java.util.logging.Logger使用具体解释

    java.util.logging.Logger不是什么新奇东西了,1.4就有了,但是由于log4j的存在,这个logger一直沉默着,事实上在一些測试性的代码中,jdk自带的logger比log4j ...

  5. Android移动网络如何抓取数据包

    1)下载tcpdump工具 tcpdump(dump the traffic on a network)是Linux中强大的网络数据采集分析工具之一,可以将网络中传送的数据包头完全截获下来提供分析.它 ...

  6. Win10 安装msi 提示2502、2503的错误代码 -- 命令提示符(管理员) -- msiexec /package

    前言: 归根到底是权限不够导致的.win7应该不会有这个问题.     解决方法: 方法1:临时安装方法 1.鼠标移到桌面左下角->右键(或者直接: WIN+X键),命令提示符(管理员):2.输 ...

  7. 【RF库Collections测试】Set To Dictionary

    Name:Set To DictionarySource:Collections <test library>Arguments:[ dictionary | *key_value_pai ...

  8. Unity中SendMessage和Delegate效率比较

    网上直接搜的代码.需要的使用也简单,所以就不过多说明. 但是网上都说,他们之间的差距,delegate比较快,效果高.怎么个高法呢?还是自己来测试下时间. 故此, 个人之用来比较下时间差别. 一.直接 ...

  9. orcale增量全量实时同步mysql可支持多库使用Kettle实现数据实时增量同步

    1. 时间戳增量回滚同步 假定在源数据表中有一个字段会记录数据的新增或修改时间,可以通过它对数据在时间维度上进行排序.通过中间表记录每次更新的时间戳,在下一个同步周期时,通过这个时间戳同步该时间戳以后 ...

  10. 【LINUX】SVN 代码提交之后。同步到web目录下

    1  当你使用svn在成功提交一个新版本的时候,svn仓库目录下的hook文件夹下的post-commit脚本会运行 用shell写一个脚本,在提交完版本后,自动在web目录运行一下svn updat ...