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 ...
随机推荐
- scjp考试准备 - 11 - 类型转换2
题目如下: interface Foo{} class Alpha implements Foo{} class Beta extends Alpha{} public class Delta ext ...
- Java泛型中的标记符含义
Java泛型中的标记符含义: E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number ...
- C# imgage图片转base64字符/base64字符串转图片另存成
//图片转为base64编码的字符串 protected string ImgToBase64String(string Imagefilename) { try { Bitmap bmp = new ...
- Git GUI 的使用
下面,我们开始使用Git Gui 如果你想init一个本地的git仓库,到你的代码根目录下,右键选择Git Init Here 这时,你会发现在代码根目录下,生成了一个.git的隐藏属性目录. 再选择 ...
- nyoj-5-kmp裸题
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=5 kmp统计匹配串出现次数,贼尴尬好久没做字符串题目,一开始求得是文本串的next ...
- 《The Cg Tutorial》阅读笔记——动画 Animation
这段时间阅读了英文版的NVidia官方的<The Cg Tutorial>,借此来学习基本的图形学知识和着色器编程. 在此做一个阅读笔记. 本文为大便一箩筐的原创内容,转载请注明出处,谢谢 ...
- centos 使用yum安装MySQL 5.7
想在centos上安装一个MySQL,使用yum install mysql-server 安装提示仓库没有包,也是醉了. 找了很多博客,发现一个很好用的,推荐给大家. 地址:https://blog ...
- PostgreSQL EXPLAIN执行计划学习--多表连接几种Join方式比较
转了一部分.稍后再修改. 三种多表Join的算法: 一. NESTED LOOP: 对于被连接的数据子集较小的情况,嵌套循环连接是个较好的选择.在嵌套循环中,内表被外表驱动,外表返回的每一行都要在内表 ...
- C++静态数据成员实现
静态数据成员是在一个类中用关键字static声明的数据成员.在C++中,一般使用静态成员来代替C语言的全局变量,以达到数据共享.C和C++的全局变量有一定的局限性,可以任意被修改,也容易和其它的变量名 ...
- 手把手教你怎么用ArcgisOnline发布地图服务
Arcgis推出了Arcgis Online,但是大家都不知道这是个什么东西,怎么用这个东西,今天这篇文章手把手的教你如何使用Arcgisonline发布地图服务. 一.ArcgisOnline简介 ...