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 ...
随机推荐
- 获取机器网卡的物理(MAC)地址
<?php /** * 获取机器网卡的物理(MAC)地址* 目前支持WIN/LINUX系统 * 编辑: www.jbxue.com**/ class MacAddInfo { ...
- getTime 方法
转自http://www.yesky.com/imagesnew/software/javascript/html/jsmthgettime.htm getTime 方法返回 Date 对象中的时间值 ...
- tomcat 高并发配置 与优化
公司的一个服务器使用Tomcat6默认配置,在后台一阵全点击服务器就报废了,查了一下就要是PERMSIZE默认值过小造成(16-64) TOMCAT_HOME/bin/catalina.sh 添加一行 ...
- opewrt上传文件
设备上运行的openwrt,当tftp和ftp都无法使用时,可以使用命令scp在两台linux设备上copy文件. 当设备启动起来后,输入命令: scp hbg@192.168.2.32:/home/ ...
- css3 media媒体查询器用法总结 兼容ie8以下的方法
总结一下响应式设计的核心CSS技术Media(媒体查询器)的用法. http://www.360doc.com/content/14/0704/06/10734150_391862769.shtml ...
- flex、As 3.0 小知识
<s:CheckBox id="checkBox" x="10" y="5" label="{new ObjectProx ...
- Nginx配置性能优化与压力测试webbench【转】
这一篇我们来说Nginx配置性能优化与压力测试webbench. 基本的 (优化过的)配置 我们将修改的唯一文件是nginx.conf,其中包含Nginx不同模块的所有设置.你应该能够在服务器的/et ...
- mysql日志详细解析【转载】
转自:http://pangge.blog.51cto.com/6013757/1319304 MySQL日志: 主要包含:错误日志.查询日志.慢查询日志.事务日志.二进制日志: 日志是mysql数据 ...
- Swift 学习笔记 (一)
原创: 转载请注明出处 Extention try catch rxSwift internal public private var let as as? 强转 ? ! didSe ...
- GetClientRect
这个函数好像就是对应于视口的,获取视口的宽高 #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPAR ...