题意:略

思路:利用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. 单网卡安装neutron

    devstack中机器只有一个物理网卡,如何设置neutron中的external网络? 方式是: 创建一个linux bridge和veth,把eth0和veth1加入到brige,用veth的另一 ...

  2. CSS 实现隐藏滚动条同时又可以滚动(转)

    CSS 实现隐藏滚动条同时又可以滚动 移动端页面为了更接近原生的体验,是否可以隐藏滚动条,同时又保证页面可以滚动? 使用 overflow:hidden 隐藏滚动条,但存在的问题是:页面或元素失去了滚 ...

  3. python学习笔记(excel+requests)

    已经可以对excel简单的操作后 可以开始通过excel写测试用例 读取用例 执行用例 提前写好execl 如图: 下面是代码: #!/usr/bin/env python # -*- coding: ...

  4. Python StringIO实现内存缓冲区中读写数据

    StringIO的行为与file对象非常像,但它不是磁盘上文件,而是一个内存里的“文件”,我们可以像操作磁盘文件那样来操作StringIO.这篇文章主要介绍了Python StringIO模块,此模块 ...

  5. sql server数据库课程设计分析

    课题:能源管理收费系统 系统功能的基本要求: (1)用户基本信息的录入:包括用户的单位.部门.姓名.联系电话.住址 : (2)用户水.电.气数据的录入(每个月的数据的录入): (3)水.电.气价格的管 ...

  6. UI-UIScrollView

    - (void)viewDidLoad { [super viewDidLoad]; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMa ...

  7. react: navigator

    1.page js import React from "react"; import {Link} from "react-router-dom"; impo ...

  8. 【git】git知识梳理(一):基本操作&远程控制&分支管理

    (一)基本操作:  git中所有文件一共有三个状态:已提交,已暂存,已修改. 三个工作区域: git目录:.git文件夹,每次拷贝其实只拷贝git目录 工作目录:文件和目录都是从git目录中压缩对象数 ...

  9. AS3中以post和get方式提交数据

    这里主要介绍在as3中用URLRequest对像来post或get数据到服务器. post用于大数据量的提交,get用于小数据量的提交. as3中提交数据: POST方式: 1.新建一个test.fl ...

  10. canvas - 圆圈内 hover效果

    链接