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 ...
随机推荐
- java-ConcurrentLinkedQueue 简单使用
import java.util.concurrent.ConcurrentLinkedQueue; public class CacheTest { /** * * offer(E e) 将指定元素 ...
- tensorflow conv2d的padding解释以及参数解释
1.padding的方式: 说明: 1.摘录自http://stackoverflow.com/questions/37674306/what-is-the-difference-between-sa ...
- iOS-证书真机调试
开发者账号分类 个人的 99$ 申请简单,付钱就行,688人民币 企业的 99$ 申请复杂,需要“邓白氏”认证,可以确认企业是合法有效的 可以管理团队开发 商业的 299$ 也需要邓白氏 ...
- python 2 3 读写中文文件 使用codecs最方便
codecs进行文件的读取 python给我们提供了一个包codecs进行文件的读取,这个包中的open()函数可以指定编码的类型: import codecs f = codecs.open('te ...
- 【scala】匿名函数和闭包
函数的类型和值 Scala是一种纯面向对象的语言,每个值都是对象.Java是一种不全面向对象的语言. Scala也是一种函数式语言,其函数也能当成值来使用.Java则是指令试编程. 但是Scala同时 ...
- python:webbrowser
import webbrowser webbrowser.open_new_tab('www.baidu.com')
- Linux操作系统中的文件目录结构详细介绍
"/" :Linux文件系统的入口.也是最高一级的目录. "/bin":基本系统所需要的命令,功能和"/usr/bin"类似,这个目录下的文 ...
- CSS: The resize Property
用户手动调节输入框样式: <!DOCTYPE html> <html> <head> <style> div { border: 2px solid; ...
- h5启动原生APP总结
许久没有写博客了,最近有个H5启动APP原生页面的需求,中间遇上一些坑,看了些网上的实现方案,特意来总结下 一.需要判断客户端的平台以及是否在微信浏览器中访问 1.客户端判断 在启动APP时,Andr ...
- Android中从SD卡中获取歌词并与歌曲同步
先看看效果图吧,再看代码 转换文件的编码格式 package com.xm; import java.io.BufferedInputStream; import java.io.BufferedRe ...