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 ;
}

pat 甲级 1056. Mice and Rice (25)的更多相关文章

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

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

  3. 1056. Mice and Rice (25)

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

  4. PAT甲级——A1056 Mice and Rice

    Mice and Rice is the name of a programming contest in which each programmer must write a piece of co ...

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

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

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

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

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

随机推荐

  1. nodejs 实现图片上传

    1.首先在目录下的运行cmd,执行以下命令 npm install multer; 2.在router下新建upload.js let express = require('express');let ...

  2. k8s的储存方式简述

    pod中的存储卷类型:1.emptyDir:用于临时储存空间,无持久性储存功能,生命周期同pod容器,pod删除后,数据不再存在.2.gitRepo:pod创建时,自动将云端仓库中的文件克隆到pod挂 ...

  3. vue.js 服务端渲染nuxt.js反向代理nginx部署

    vue.js的官方介绍里可能提到过nuxt.js,我也不太清楚我怎么找到这个的 最近项目vue.js是主流了,当有些优化需求过来后,vue还是有点力不从心, 比如SEO的优化,由于vue在初始化完成之 ...

  4. C++ 虚函数实例

    #include <iostream> using namespace std; //线 class Line { public: Line(float len); ; ; protect ...

  5. JDK各版本新特性浅谈

    JDK 5.0 自动拆装箱 枚举 可变参数 泛型 For -each 内省 静态导入 JDK 6.0 console开发控制台程序 轻量级HTTP ServerAPI 支持脚本语言 使用Compile ...

  6. OpenCV学习笔记(四) Mat的简单操作

    转自:OpenCV Tutorial: core 模块. 核心功能 改变图像对比度和亮度:convertTo 可以把  看成源图像像素,把  看成输出图像像素.这样一来,调整亮度和对比度的方法可表示为 ...

  7. getsupportfragmentmanager 没有这个方法

    让activity继承自fragmentactivity就行了.

  8. 第八届蓝桥杯C/C++ B组省赛----分巧克力

    分巧克力 问题描述 儿童节那天有K位小朋友到小明家做客.小明拿出了珍藏的巧克力招待小朋友们. 小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形. 为了公平起见,小明需要从这 N 块巧 ...

  9. 扩展MarkDown表格

    一直不知道表格中的:是什么意思,看了GcsSloop的这篇文章后恍然大悟,做下记录. 原文链接 第二行分割线部分可以使用 : 来控制内容状态 MarkDown : | 默认 | 靠右 | 居中 | 靠 ...

  10. Windows Server 2012之活动目录域服务的卸载

    Windows Server 2012之活动目录域服务的卸载 2012-07-11 06:27:35 标签:Windows Server 2012 活动目录域服务 卸载 原创作品,允许转载,转载时请务 ...