题意:略

思路:利用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. kolla all-in-one 安装

    http://docs.openstack.org/developer/kolla/ 使用了Docker containers and Ansible playbooks 目前在Fedora/Ubun ...

  2. Cacti的基本安装配置

    ////////////////////cacti///////////////////////////常用的监控软件有:cacti.nagios.zabbix等 cacti 重图形.有数据历史.需要 ...

  3. angularjs实现星星评分

    angularjs实现星星评分 自定义指令 app.directive('myStars', function () { return { require : '?ngModel', // ?ngMo ...

  4. LeetCode第[26]题(Java):Remove Duplicates from Sorted Array 标签:Array

    题目难度:Easy 题目: Given a sorted array, remove the duplicates in-place such that each element appear onl ...

  5. Web2.0 TA 问题记录

    记录一下上学期在当Web2.0 TA的时候遇到过的小朋友们问过的问题,可能会成为以后我开发上遇到的问题. 1. 元素的背景默认是boader origin的,也就是说是从边框开始延伸的. 但如果对bo ...

  6. mysql数据库优化课程---7、网站的搜索技术怎么选

    mysql数据库优化课程---7.网站的搜索技术怎么选 一.总结 一句话总结: 1.量很小(像小网站)---like2.量大一点()---标签3.量超级大(像百度)---搜索引擎 1.数据库中取一列比 ...

  7. mysql数据库优化课程---6、mysql结构化查询语言有哪些

    mysql数据库优化课程---6.mysql结构化查询语言有哪些 一.总结 一句话总结:主要分为四类 1.DCL 数据控制语言1)grant2)commit3)rollback 2.DDL 数据定义语 ...

  8. DOM冒泡事件

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

  9. WPF中的事件列表 .

    以下是WPF中的常见事件汇总表(按字母排序),翻译不见得准确,但希望对你有用. 事件 描述 Annotation.AnchorChanged 新增.移除或修改 Anchor 元素时发生. Annota ...

  10. Installing Forms Developer 10g and Reports 32-bit on 64-bit Windows versions(win7 or win10)

    E-Business Suite 12.1 and 12.2 require Forms Developer 10g and Reports Designer 10g.  Forms Develope ...