有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)-模拟题的更多相关文章

  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 甲级 1056. Mice and Rice (25)

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

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

  4. 1056. Mice and Rice (25)

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

  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 (Advanced Level) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  7. PAT甲题题解-1017. Queueing at Bank (25)-模拟

    有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...

  8. PAT甲题题解-1044. Shopping in Mars (25)-水题

    n,m然后给出n个数让你求所有存在的区间[l,r],使得a[l]~a[r]的和为m并且按l的大小顺序输出对应区间.如果不存在和为m的区间段,则输出a[l]~a[r]-m最小的区间段方案. 如果两层fo ...

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

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

随机推荐

  1. MongoDB基础之 用户和数据库基于角色的访问控制

    mongod 关键字参数:--auth 默认值是不需要验证,即 --noauth,该参数启用用户访问权限控制:当mongod 使用该参数启动时,MongoDB会验证客户端连接的账户和密码,以确定其是否 ...

  2. 团队作业8-测试与发布(beta阶段)

    小组成员 [组长]金盛昌(201421122043).刘文钊(20142112255).陈笑林(201421122042) 张俊逸(201421122044).陈志建(201421122040).陈金 ...

  3. 异步IO的概念

    同步IO是阻塞IO: 异步IO分为两种:1.主动查询是否有数据:2.被动监听是否有数据状态. https://www.cnblogs.com/euphie/p/6376508.html

  4. 使用vs2010编译lua5.1源代码生成lua.lib

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/wangbin_jxust/article/details/37557807 一.打开vs2010 二 ...

  5. Centos7 Nginx 开机启动

    Centos 系统服务脚本目录: 用户(user) 用户登录后才能运行的程序,存在用户(user) /usr/lib/systemd/ 系统(system) 如需要开机没有登陆情况下就能运行的程序,存 ...

  6. oracle 删除重复数据

    1.找出重复数据 select count(1),uuid  from ts.test group by uuid having count(1)>1 order by 1 desc ;---找 ...

  7. persistence_timeout ,域名请求登录后一操作即被踢出,,KeepAlive,lvs

    virtual_server *.*.*.* 80 { delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 120 protocol TCP ...

  8. Kubernetes1.91(K8s)安装部署过程(七)--coredns安装

    为了是集群内的服务能使用dns进行服务解析,集群内需要使用dns服务器,可以按照kube官方dns,即kubedns或者其他的dns,比如coredns, 本例中按照的为coredns,按照简单,编辑 ...

  9. 十分钟教你使用NoteExpress

    http://www.a-site.cn/article/761794.html 如果你正走在读研的路上,不管是什么专业,日常生活中都少不了读文献.读文献和读文献. 与其等到文献堆积如山,给阅读和使用 ...

  10. 解决IDEA因分配内存而引起的卡顿

    解决IDEA分配内存不足引起卡顿的问题 在使用IDEA的过程中,经常会运行一段时间后程序卡顿.一段代码可能要敲很久或者出现死机状态,严重影响代码书写速度.经查阅资料,IDEA的自动分配内存最大只有75 ...