有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. 乘风破浪:LeetCode真题_035_Search Insert Position

    乘风破浪:LeetCode真题_035_Search Insert Position 一.前言 这次的问题比较简单,也没有限制时间复杂度,但是要注意一些细节上的问题. 二.Search Insert ...

  2. SDN期末作业-通过SDN的应用实现负载均衡

    负载均衡程序 1.程序链接:https://github.com/424baopu/software/tree/master/LoadBalance 2.场景 topo: 场景描述: 服务器host ...

  3. Beta 冲刺 (1/7)

    Beta 冲刺 (1/7) 队名:洛基小队 峻雄(组长) 已完成:β版的初步计划 后两天计划:设计角色的技能树 剩余任务:角色的技能 困难:关于技能施放以及相关伤害计算等的代码 非易 已完成:角色交互 ...

  4. tcp/ip 数据进入协议栈时的封装及分用过程图

  5. python-celery定时提交任务

    pip install celery 使用消息中间件:RabbitMQ/Redis app=Celery('任务名',backend='xxx',broker='xxx') 基本使用 import c ...

  6. pytorch GPU的程序kill后未释放内存

    使用PyTorch设置多线程(threads)进行数据读取(DataLoader),其实是假的多线程,他是开了N个子进程(PID都连着)进行模拟多线程工作,所以你的程序跑完或者中途kill掉主进程的话 ...

  7. Spring framework3.2整合hibernate4.1报错:No Session found for current thread

    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransact ...

  8. OpenCV——SURF特征检测、匹配与对象查找

    SURF原理详解:https://wenku.baidu.com/view/2f1e4d8ef705cc1754270945.html SURF算法工作原理 选择图像中的POI(Points of i ...

  9. vector使用小结

    1.创建vector容器: std::vector<int> data; std::vector<int> data(20);大小20,自动赋值为0 std::vector&l ...

  10. Jquery简单的placeholder效果

    Jquery简单的placeholder效果 由于IE6-IE9不支持HTML5中的placeholder,所以自己依赖于Jquery简单的写了一个,供参考! 先看看效果吧!如下JSFiddle地址 ...