PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<stack>
#include<vector>
using namespace std; const int maxn=+;
struct X
{
int val;
int id;
}s[maxn];
int n,m;
int ans[maxn];
int h[maxn],cnt;
queue<X>Q[]; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&s[i].val);
for(int i=;i<=n;i++) s[i].id=i;
for(int i=;i<=n;i++)
{
int f; scanf("%d",&f); f++;
Q[].push(s[f]);
} int now=; while()
{
memset(h,,sizeof h);
if(Q[now].size()==)
{
ans[Q[now].front().id]=;
break;
} while()
{
if(Q[now].size()<=m)
{ X tmp; tmp.val=-;
while(!Q[now].empty())
{
h[Q[now].front().id]=;
if(Q[now].front().val>tmp.val) tmp=Q[now].front();
Q[now].pop();
}
h[tmp.id]=;
Q[now^].push(tmp);
break;
}
else
{
X tmp; tmp.val=-;
for(int i=;i<m;i++)
{
h[Q[now].front().id]=;
if(Q[now].front().val>tmp.val) tmp=Q[now].front();
Q[now].pop();
}
h[tmp.id]=;
Q[now^].push(tmp);
}
}
now=now^;
for(int i=;i<=n;i++)
if(h[i]==) ans[i]=Q[now].size()+;
}
for(int i=;i<=n;i++)
{
printf("%d",ans[i]);
if(i<n) printf(" ");
else printf("\n");
}
return ;
}
PAT (Advanced Level) 1056. Mice and Rice (25)的更多相关文章
- 【PAT甲级】1056 Mice and Rice (25 分)
题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...
- 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 ...
- 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)
时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...
- 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) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1110. Complete Binary Tree (25)
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...
随机推荐
- 在windows命令行窗口下执行:查看所有的端口占用情况
开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...
- Eclipse/MyEclipse中使用复制粘贴功能卡的解决办法
最近在MyEclipse中编辑代码时,使用快捷键进行复制粘贴,经常会导致编辑器短暂的停顿,光标不跟随,居然反应不过来,几近假死. 想来想去应该是编辑上的什么配置或者是IDE的什么功能导致,于是进入Pr ...
- [nginx] 网上最全面nginx教程(近100篇文章整理)
转载:http://bbs.linuxtone.org/thread-25588-1-1.html Nginx基础 1. nginx安装 2. nginx 编译参数详解 3. nginx安装配置 ...
- XStream的使用方法、简单使用方法、xml的解析方法
下面介绍的是在Android Studio中的使用 Android Studio中目前支持的Xstream最高版本是xstream-1.4.7.jar,大家可以在网上下载,我的是在开源中国项目中有这个 ...
- beagleboneblack HDMI不能显示
beagleboneblack 接上HDMI到电视上,没有显示画面 看了资料之后才知道 http://elinux.org/Beagleboard:BeagleBoneBlack_HDMI#Conn ...
- xmlHTTP技术资料
一.数据库远程管理技术 基于互联网的广域网现代应用中的一个重要环节是数据库远程监控.首先简单回顾一下互联网上的数据库远程管理技术的发展过程和方式: 早期通过编写CGI-BIN程序模块进行数据库远程管理 ...
- 四种xml的解析方式
这篇文章是我上网找资料,加上自己总结了一些而得 资料来源: http://www.cnblogs.com/allenzheng/archive/2012/12/01/2797196.html http ...
- java应用测试报告生成(一): sonarqube配合Jenkins生成测试报告及覆盖率
环境准备: 1.Jenkins集成环境(安装 sonarqube插件) 2.安装sonarqube服务(下载sonarqube安装包并解压,目录到"sonarqube-5.4/bin/lin ...
- codeforces 689B Mike and Shortcuts 最短路
题目大意:给出n个点,两点间的常规路为双向路,路长为两点之间的差的绝对值,第二行为捷径,捷径为单向路(第i个点到ai点),距离为1.问1到各个点之间的最短距离. 题目思路:SPFA求最短路 #incl ...
- Struts2实现国际化
public class I18nAction extends ActionSupport { private static final long serialVersionUID = -693330 ...