pat 甲级 1056. Mice and Rice (25)
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 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)的更多相关文章
- 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 ...
- 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 ...
- 1056. Mice and Rice (25)
时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...
- 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 ...
- 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 ...
- 【PAT甲级】1056 Mice and Rice (25 分)
题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...
- PAT甲题题解-1056. Mice and Rice (25)-模拟题
有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...
- PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- pat1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and ...
随机推荐
- Oracle10g安装过程中的Configuration Assistant配置失败的问题。
前几天安装Oracle的时候碰到了一个小问题,是在最后配置的时候,出现失败提示如下 失败提示:一些 Configuration Assistant 失败.强烈建议您此时重试这些 Configurati ...
- "mysql"."innodb_table_stats" not found 故障解决
故障描述 "mysql"."innodb_table_stats" 表不存在 "mysql"."innodb_index_stat ...
- Mysql--数据定义语言(DDL)
DDL(Data Definition languages)数据定义语言,这些语句主要定义了不同的数据段,数据表.列.索引等操作,主要关键字有create.drop.alter. 一. 数据库的操作 ...
- php扩展开发-快速上手
系统环境CentOS release 6.5 (Final) PHP版本php-5.6.27 扩展开发需要有php环境及php的源代码,我的PHP安装目录/home/zhangxiaomin/stud ...
- Redis之Hash类型操作
接口IRedisDaoHash: package com.net.test.redis.base.dao; import com.net.test.redis.base.entity.UserPsg; ...
- 用Python学分析 - 单因素方差分析
单因素方差分析(One-Way Analysis of Variance) 判断控制变量是否对观测变量产生了显著影响 分析步骤 1. 建立检验假设 - H0:不同因子水平间的均值无差异 - H1:不同 ...
- web开发框架Flask学习二
jinja2模板规范 在当前项目中创建一个文件为templates的文件夹,将其设置为模板文件夹,新建的html为模板页面, 在视图函数中使用render_template(".html的文 ...
- 自定义 popWindow弹框 工具包
前言:因为Android 没有像IOS一样的ActionSheet,虽然在github上看到有一些类似ActionSheet的库,总觉得不好用,不如自己写一个弹框通用类,样式全部自已来多好. Step ...
- iview框架 两侧弹框 出现第二层弹框 一闪而过的问题
分析原因:寡人怀疑可能是,两层弹出框 采用的是一个开关值,发生了覆盖 解决方式 是在第二层弹框外套层计时器 源代码如下: 修改后为:
- TCP/IP网络编程之套接字的多种可选项
套接字可选项进而I/O缓冲大小 我们进行套接字编程时往往只关注数据通信,而忽略了套接字具有的不同特性.但是,理解这些特性并根据实际需要进行更改也十分重要.之前我们写的程序在创建好套接字后都是未经特别操 ...