1056 Mice and Rice
题意:略
思路:利用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的更多相关文章
- PAT 1056 Mice and Rice[难][不理解]
1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...
- pat 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- 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 ...
- 1056. Mice and Rice (25)
时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...
- 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 ...
- 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 ...
- PAT甲题题解-1056. Mice and Rice (25)-模拟题
有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...
- PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- PAT 1056 Mice and Rice
#include <cstdio> #include <climits> #include <cstdlib> #include <vector> #i ...
随机推荐
- JNI_Z_06_方法的操作(没有String类型的参数)_父类的同名方法
1.关键在于: 使用的 method id 是 子类的 还是 父类的,而 父类methodID的获取 必须使用 父类的class对象. 2.VC6(CPP)的DLL代码: #include<st ...
- Spark- 使用hiveContext时提交作业报错
在spark上操作hive时不需要搭建hive环境,只需要从现有的hive集群中hive的conf目录下拷贝 hive-site.xml 到spark的conf目录下即可提交程序运行 出现报错 Cau ...
- Android报错Type Error executing aapt: Return code -1 - HTTP 500
我的做法是(乱蒙对的) 把menu.xml干掉!,对的你没看错! 当然其他人方案:如下 1.http://stackoverflow.com/questions/10699439/aapt-filin ...
- react 文章
1.http://www.ruanyifeng.com/blog/2016/09/react-technology-stack.html (React 技术栈系列教程) 2.http://www.ru ...
- (http请求+cookie)的交互流程
如果步骤5携带的是过期的cookie或者是错误的cookie,那么将认证失败,返回至要求身份认证页面. 当前 Cookie 有两个版本:Version 0 和 Version 1.通过它们有两种设置响 ...
- DOS命令说明
(转自:http://blog.csdn.net/mydriverc/article/details/2047152) 1 errorlevel dir cd md rd del ren cls ty ...
- shell编程实例1
1.vim hello.sh 2. #!bin/bash echo "hello world!" 3.chmod +x hello.sh 4.source hello.sh ls ...
- 再论typedef
typedef 定义(或者叫重命名)类型而不是变量 1.类型是一个数据模板,变量是一个实在的数据.类型是不占内存的,而变量是占内存的. 2.面向对象的语言中:类型的类class,变量就是对象. #in ...
- WeChat on Web 部分功能模拟实现
Flask from flask import Flask,request,render_template,session,jsonify import time import requests im ...
- 《Scala入坑笔记》缘起 3天就搞了一个 hello world
有小伙伴向我咨询 play framework 的问题,我就想了解一下 play framework ,按照官方的文档,要使用 SBT 安装,就掉进了 SBT 的坑. 第一坑:国外仓库太慢 安装完成后 ...