1056. Mice and Rice (25)

时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

题意:模拟,设最多x个人一组,每一轮游戏先按照游玩者玩游戏的顺序分组,每一组产生一名分数最高者,其余的人止步这一轮比赛并获得(下一轮游玩人数)+1的名次,直至决定出第一名为止。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define INF 0x3f3f3f
#define N_MAX 100000+5
int n, group;
int weight[N_MAX],Rank[N_MAX];
vector<int>permute;
int main() {
while (cin >> n >> group) {
for (int i = ; i < n; i++)scanf("%d", &weight[i]);
for (int i = ; i < n; i++) { int a; scanf("%d", &a); permute.push_back(a); }
vector<int>vec = permute, vec2; int N = vec.size();
while (N > group) {
int rank = (N%group == ) ? N / group + : N / group + ;
int i = , tmpi = group;
while () {
int max_wei = , id;
for (; i < tmpi; i++) {
if (max_wei < weight[vec[i]]) {
max_wei = weight[vec[i]];
id = vec[i];
}
}
vec2.push_back(id); //没落选的
for (int k = tmpi - group; k < tmpi; k++)//落选的确定排名
if (vec[k] != id)Rank[vec[k]] = rank;
if (tmpi == N)break;
tmpi += group;
if (tmpi > N)tmpi = N;
}
vec = vec2;
N = vec.size();
vec2.clear();
}
if (N > ) {//最后一组
int max_wei = ,id;
for (int i = ; i < vec.size();i++) {
if (max_wei < weight[vec[i]]) {
max_wei = weight[vec[i]];
id = vec[i];
}
}
for (int i = ; i < vec.size();i++) {
if (vec[i] != id)Rank[vec[i]] = ;
else Rank[vec[i]] = ;
}
} for (int i = ; i < n; i++)
printf("%d%c", Rank[i], i + == n ? '\n' : ' ');
} return ;
}

最新文章

  1. 报错记录:getOutputStream() has already been called for this response
  2. nginx日志切割脚本
  3. HTML5+AJAX原生分块上传文件的关键参数设置
  4. Description DisplayName Display的关系
  5. 如何开启SQL Server 2008的远程联机
  6. 转载:JMS-ActiveMQ浅析
  7. java 多个设备,锁定先后顺序
  8. python 二分法查找
  9. tengine+lua的安装步骤
  10. IntelliJ IDEA 14.0.2破解注册码文件(2015年06月08日)
  11. php 文件下载 以及 file_exists找不到文件的解决方案
  12. jQuery关于mouseover和mouseenter的区别
  13. Java-List泛型的用处(能够使用传入泛型对象的方法)
  14. (转)Java并发编程:深入剖析ThreadLocal
  15. myEclipse 配置tomcat清除缓存
  16. &lt;Android基础&gt; (六) 数据存储 Part 1 文件存储方式
  17. Linux 下统计Apache每分钟的并发数
  18. 26.mysql日志
  19. 面试:用快排实现数组中的第K大的数
  20. java输出重定向

热门文章

  1. SummerVocation_Learning--java的线程死锁
  2. 52shaidan.net
  3. Spring @Transactional 浅谈
  4. win10下安装mysql-5.7.23-winx64
  5. Fakeapp 入门教程(2):使用篇!
  6. Python知识点进阶——细节问题
  7. 动态规划:HDU1059-Dividing(多重背包问题的二进制优化)
  8. kafka 的offset的重置
  9. Session超时和莫名丢失的原因与处理办法
  10. 1、HTML基础总结 part-1