题意:略

思路:利用queue来模拟一轮一轮的比赛。自己第一遍做的时候完全没有用queue做的意识,代码写的贼烦最后还只得了17分,非常郁闷。通过本题反映出对queue的应用场景季度不熟悉,STL里面用的最少的就是队列了。另外还有一点,在当前这一轮被淘汰的老鼠排名均为当前组数+1,这一点我也没看出来,自己做的时候拐了18个弯去实现这一点,真是惭愧!

代码:

#include <cstdio>
#include <queue>
using namespace std;

struct Mouse{
    int w;
    int r;
}mouse[];

int main()
{
    //freopen("pat.txt","r",stdin);
    int n,step;
    scanf("%d%d",&n,&step);
    int order;
    queue<int> q;
    ;i<n;i++)
        scanf("%d",&mouse[i].w);
    ;i<n;i++){
        scanf("%d",&order);
        q.push(order);
    }
    int temp=n,group;//temp为当前这一轮参加的老鼠个数,初始化为n;group为组数
    ){
        //计算这一轮的分组
        group=(temp%step== ? temp/step : temp/step+);
        //遍历每一组,找出该组的老鼠质量的最大值
        ;i<=group;i++){
            int maxIdx=q.front();//记录该组质量最大的下标
            ;j<=step;j++){          //用于判断最后一组不满step个的情况
                )*step+j>temp) break;
                if(mouse[q.front()].w > mouse[maxIdx].w)
                    maxIdx=q.front();
                mouse[q.front()].r=group+;//关键,规律
                q.pop();
            }
            //maxIdx即这一组的胜利者,push进队列,进入下一轮的比赛
            q.push(maxIdx);
        }
        temp=group;//下一轮参加比赛的老鼠个数就是这一轮的组数
    }
    mouse[q.front()].r=;
    printf(].r);
    ;i<n;i++)
        printf(" %d",mouse[i].r);
    ;
}

1056 Mice and Rice的更多相关文章

  1. PAT 1056 Mice and Rice[难][不理解]

    1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...

  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 甲级 1056 Mice and Rice (25 分) (队列,读不懂题,读懂了一遍过)

    1056 Mice and Rice (25 分)   Mice and Rice is the name of a programming contest in which each program ...

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

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

  7. PAT甲题题解-1056. Mice and Rice (25)-模拟题

    有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...

  8. PAT (Advanced Level) 1056. Mice and Rice (25)

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

  9. PAT 1056 Mice and Rice

    #include <cstdio> #include <climits> #include <cstdlib> #include <vector> #i ...

随机推荐

  1. scala学习手记18 - Any和Nothing

    Any 前面已经有两次提到过:在scala中,Any类是所有类的超类. Any有两个子类:AnyVal和AnyRef.对应Java直接类型的scala封装类,如Int.Double等,AnyVal是它 ...

  2. C语言中链接影响程序的细节

    参考:<深入理解计算机系统>  7.61节  链接器如何解析多重定义的全局符号 基本的原则是这样的:对于所有的全局符号,函数和已初始化的全局变量是强符号,未初始化的全局变量是弱符号. Un ...

  3. ps切图步骤

    1.复制图层到新建 2.alt + i + r  裁剪 依次按 3.ctrl + alt + shift + s  保存 裁剪图标  复制到图层 , 删除背景,并复制样式 就可以做到 背景透明.

  4. Entity Framework 6 Code First 系列:无需修改实体和配置-在MySql中使用和SqlServer一致的并发控制

    无需修改实体和配置,在MySql中使用和SqlServer一致的并发控制.修改RowVersion类型不可取,修改为Timestamp更不可行.Sql Server的RowVersion生成一串唯一的 ...

  5. Web API与AJAX:理解FormBody和 FormUri的WebAPI中的属性

    这是这一系列文章"与 AJAX 的 Web API".在这一系列我们都解释消耗 Web API rest 风格的服务使用 jQuery ajax() 和其他方法的各种方法.您可以阅 ...

  6. 分享知识-快乐自己:MYSQL之內链接 左链接 右链接 区别

    MYSQL中可以通过内外键链接,将有关系的表中数据合并到一起进行条件筛选: 首先创建两个新表,数据如下: student 表数据: score 表数据: 可以看到students表中stu_id为16 ...

  7. charles抓包工具的使用:手机抓包设置和安装证书

    一. 设置手机抓包 第一步:在charles里设置允许手机联网的权限,并设置接入接口 在Charles的菜单栏上选择"Proxy"->"Proxy Settings ...

  8. zzuli 2179 最短路

    2179: 紧急营救 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 9 SubmitStatusWeb Board Descri ...

  9. MongoCola使用教程 2 - MongoDB的Replset 初始化和配置

    前言 首先再次感谢博客园的各位朋友.正是你们的关注才让我有信心将这个工具开发下去. 这周同样也有热心网友对于MongoCola存在的问题给予了反馈. 这次工具更新到了版本1.20,强化的地方是增加了R ...

  10. react antd form多组表单数据处理

    import React from 'react'; import {Form, InputNumber, Input, DatePicker, Button, Select, Icon} from ...