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只为一组, ...
随机推荐
- VS 0x80041FEB
在打开from设计界面时,报错. 解决方法:将项目中Properties文件中licenses.licx删除,重新建立一个空的licenses.licx文件放到项目中. 重新打开界面,解决
- 容器内部设置JVM的Heap大小
容器内部利用脚本来获取容器的CGroup资源限制,并通过设置JVM的Heap大小. Docker1.7开始将容器cgroup信息挂载到容器中,所以应用可以从 /sys/fs/cgroup/memory ...
- MP实战系列(十八)之XML文件热加载
你还在为每次修改XML文件中的SQL重新启动服务器或者是等待几分钟而烦恼吗? 配置了热加载即可解决你的这个问题. 这就是XML文件热加载的目的,减少等待时间成本,提高开发效率. SSM框架配置(Spr ...
- Android 下拉刷新上拉加载PullToRefresh
https://github.com/823546371/PullToRefresh http://www.jianshu.com/p/0f5d0991efdc
- IDEA创建Scala项目
一.安装插件 见Scala入门篇 二.新建项目 选择new project,其中SBT相当于精简版的maven,其他的待补充.这里选择IDEA 填写信息,选择Scala SDK 在src目录下新建Sc ...
- c# Login UI with background picture animation
准备4张图片 UI control: <Grid x:Class="Test1.MainBgAd" xmlns="http://schemas.microsoft. ...
- Python+Selenium爬取动态加载页面(2)
注: 上一篇<Python+Selenium爬取动态加载页面(1)>讲了基本地如何获取动态页面的数据,这里再讲一个稍微复杂一点的数据获取全国水雨情网.数据的获取过程跟人手动获取过程类似,所 ...
- mfc 纯虚函数和抽象类
纯虚函数 抽像类 一.纯虚函数 虚函数为了重载和多态的需要,有时需要在基类中定义一个纯虚函数,代码部分在子类中加以实现.定义格式如下的函数我们称为纯虚函数: ; 纯虚函数与空虚函数是有区别的; 二.抽 ...
- 一些IT中的工具介绍
1. 史上最全github使用方法:github入门到精通 2. Git教程 3. GIT与GitHub使用简介 简单来说,git是一种版本控制系统.跟svn.cvs是同级的概念.github是一个网 ...
- 【第十课】Tomcat入门
目录 1.Tomcat介绍 2.Tomcat安装部署和配置 (1)tomcat下载和解压 (2)jdk环境变量配置 (3)设置tomcat以普通用户启动 (4)查看tomcat的配置 (5)tomca ...