题意:略

思路:利用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. java PreparedStatement和statement的区别

    1. PreparedStatement接口继承Statement, PreparedStatement 实例包含已编译的 SQL 语句,所以其执行速度要快于 Statement 对象.2.作为 St ...

  2. python学习笔记(arange函数与linspace函数)

    上一篇提及到matplotlib模块.其中会涉及到numpy模块科学计数 这里总结两个数组生成函数 arange 与 linspace: #!/usr/bin/env python # -*- cod ...

  3. DOM冒泡事件

    一.注册事件的三种方式 1 on的方式 语法: 事件源.on+事件名称 = 事件处理程序 例如: btn.onclick = function(){} 细节: 只能注册一个事件处理函数 兼容: 所有主 ...

  4. Learining TypeScript (一) TypeScript 简介

    Learining TypeScript (一) TypeScript 简介 一.TypeScript出现的背景    2 二.TypeScript的架构    2 1.    设计目标    2 2 ...

  5. vue如何循环同一个echarts图表

    因为我们知道echarts图表需要一个ID节点,所以我们循环echarts同一个图表时要考虑ID节点变化问题.废话不多说,直接上demo效果. 这里有一位分析师在不同的模拟组合,这时需求要在dialo ...

  6. .Net 中的IL中间语言基本语法

    一.前言 IL是什么? Intermediate Language (IL)微软中间语言 C#代码编译过程? C#源代码通过LC转为IL代码,IL主要包含一些元数据和中间语言指令: JIT编译器把IL ...

  7. Git的origin和master分析

    首先要明确一点,对git的操作是围绕3个大的步骤来展开的(其实几乎所有的SCM都是这样) 1. 从git取数据(git clone) 2. 改动代码 3. 将改动传回git(git push) 这3个 ...

  8. windows ubuntu Android studio安装好启动没反应解决方法

     参考:http://blog.csdn.net/qq305013720/article/details/8934152 目前有三种解决方案,都是针对执行studio.bat出现错误导致andro ...

  9. ng 自定义服务

    服务的本质是对象. 创建服务的常见方式:factory(返回对象) service (方法.属性)constant(常量服务) value(变量服务) 1.factoryapp.factory('服务 ...

  10. js 变量与属性的区别

    在全局作用域下, 表明全局变量x,属性b,都是window的属性,因为在全局作用域下,浏览器默认会创建一个window对象. 说明变量x不能通过delete进行删除,但是属性y可以通过delete进行 ...