PAT甲题题解-1056. Mice and Rice (25)-模拟题
有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序。
1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组。
2.每组重量最大的进入下一轮。
让你给出每只老鼠最后的排名。
很简单,用两个数组模拟一下即可
order1存储进入当前一轮老鼠的索引顺序
order2存储进入下一轮老鼠的索引顺序
如果当前有groups个组,那么会有groups个老鼠进入下一轮,则没有进入下一轮的排名都为groups+1
如果只有一个组,那么最大的那个排名即为1。
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm> using namespace std;
const int maxn=+; struct Mice{
int weight;
int ranks;
}mice[maxn]; int order1[maxn];
int cnt1=;
int order2[maxn];
int cnt2=;
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<n;i++){
scanf("%d",&mice[i].weight);
}
for(int i=;i<n;i++){
scanf("%d",&order1[i]);
}
cnt1=n;
int rRanks=;
int groups;
while(){
rRanks++;
cnt2=;
int maxw,maxid;
groups=cnt1/m;
if(cnt1%m!=)
groups++;
for(int i=;i<cnt1;i+=m){
maxw=;
int v;
for(int j=i;j<i+m&&j<cnt1;j++){
v=order1[j];
if(mice[v].weight>maxw){
maxw=mice[v].weight;
maxid=v;
}
}
for(int j=i;j<i+m&&j<cnt1;j++){
v=order1[j];
if(v!=maxid)
mice[v].ranks=groups+;//有groups个组,那么晋级下一轮的就有groups个人,所有没晋级的并列第groups+1名。
}
order2[cnt2++]=maxid;
}
if(cnt1<=m){
mice[maxid].ranks=;
break;
}
for(int i=;i<cnt2;i++){
order1[i]=order2[i];
}
cnt1=cnt2;
}
printf("%d",mice[].ranks);
for(int i=;i<n;i++){
printf(" %d",mice[i].ranks);
}
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 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- 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 ...
- 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 (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- PAT甲题题解-1017. Queueing at Bank (25)-模拟
有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...
- PAT甲题题解-1044. Shopping in Mars (25)-水题
n,m然后给出n个数让你求所有存在的区间[l,r],使得a[l]~a[r]的和为m并且按l的大小顺序输出对应区间.如果不存在和为m的区间段,则输出a[l]~a[r]-m最小的区间段方案. 如果两层fo ...
- 【PAT甲级】1056 Mice and Rice (25 分)
题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...
随机推荐
- HDFS NameNode内存详解
前言 <HDFS NameNode内存全景>中,我们从NameNode内部数据结构的视角,对它的内存全景及几个关键数据结构进行了简单解读,并结合实际场景介绍了NameNode可能遇到的问题 ...
- 三、git管理修改
一.修改提交 如下图,Git分工作区和版本库(.git隐藏目录中). 在每次修改后 git add "file name" 其实是把修改内容提交到本地版本库的 暂存区(stage) ...
- linux,添加新硬盘的方法
一.物理机添加一块新的硬盘方法(目的是把后加的磁盘直接加在现有的上面,不用再分区挂载)1.首先要确定现有系统在那块盘上 [root@localhost ~]# df -lhFilesystem ...
- Netty入门(四)ByteBuf 字节级别的操作
Netty 中使用 ByteBuf 代替 Java NIO 提供的 ByteBuffer 作为字节的容器. 一.索引 ByteBuf 提供两个指针变量支持读和写操作,读操作使用 readerInde ...
- CentOs下MySQL5.6.32源码安装
. 安装好--安装MySQL需要的包 yum install -y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c+ ...
- Tensorflow Object Detection API 安装
git:https://github.com/tensorflow/models/tree/master/object_detection 中文文档:http://wiki.jikexueyuan.c ...
- Git——新手入门与上传项目到远程仓库GitHub(转)
Git概述 什么是Git? 刚开始对这个东西也感到挺迷茫,并且问了好多已经学习android一段时间的同学也是一头雾水,直到了解并使用之后,才体会到Git的好处以及重要意义. Git:是目前世界上最先 ...
- ethereumjs/ethereumjs-wallet
Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...
- pyspider爬取数据存入redis--2.测试数据库连通性
直接上代码 #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2017-10-27 09:56:50 # Project: re ...
- C#控件中的KeyDown、KeyPress 与 KeyUp事件浅谈
研究了一下KeyDown,KeyPress 和 KeyUp 的学问.让我们带着如下问题来说明: 1.这三个事件的顺序是怎么样的? 2.KeyDown 触发后,KeyUp是不是一定触发? 3.三个事件的 ...