有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. [LOJ 2720][BZOJ 5417][UOJ 395][NOI 2018]你的名字

    [LOJ 2720][BZOJ 5417][UOJ 395][NOI 2018]你的名字 题意 给定一个大串 \(S\) 以及 \(q\) 次询问, 每次询问给定一个串 \(T\) 和区间 \([l, ...

  2. 【Python】新建自定义个数的自定义长度名字

    # -*- coding:utf-8 -*- import random def CreateRandomName(number,length): """ :param ...

  3. win10管理员已阻止你运行此应用”解决方法

    方法/步骤 1 按WIN+R键,打开“运行”,然后输入“gpedit.msc",就是打开组策略,这个在控制面板中也可以打开. 2 在组策略里找到“计算机配置”-“Windows设置”-“安全 ...

  4. 【转】Poco 1.4.2 HTTPClientSession/HTTPRequest 使用使用代理(proxy)需要注意的一点

    Poco 1.4.2 HTTPClientSession/HTTPClientSession 在使用代理的时候,request的URI不能包含协议和主机.否则会出错. 不使用代理的时候,以下代码能正常 ...

  5. 【转】Android Service创建USB HOST通信

    之前做了一个关于Android USB通信的Case,通过Android的USB总线给Zigbee供电,和板载的Zigbee(基于Zigbee的自组网)进行通信.要使用Android的USB Host ...

  6. Node.js实战(九)之事件循环

    Node.js 是单进程单线程应用程序,但是因为 V8 引擎提供的异步执行回调接口,通过这些接口可以处理大量的并发,所以性能非常高. Node.js 几乎每一个 API 都是支持回调函数的. Node ...

  7. js中获取url后面的参数值

    方法: //获取url路径?号后面的参数值.function GetRequest() { var url = location.search; //获取url中"?"符后的字串 ...

  8. CentOS7服务器上部署深度/机器学习环境推荐首选anaconda3

    CentOS7服务器上部署深度/机器学习环境推荐首选anaconda3,亲测~~ 因为可以创建不同的环境版本或虚拟环境 CentOS7服务器安装anaconda3后,CentOS7服务器开启后自动将a ...

  9. P2731 骑马修栅栏 Riding the Fences

    题目描述 John是一个与其他农民一样懒的人.他讨厌骑马,因此从来不两次经过一个栅栏.你必须编一个程序,读入栅栏网络的描述,并计算出一条修栅栏的路径,使每个栅栏都恰好被经过一次.John能从任何一个顶 ...

  10. Mac下Qt的环境搭建

    1.分别下载并安装XCode和Command Line Tools(必须安装),安装完毕后,Clang就有了. https://developer.apple.com/downloads/ 2.下载Q ...