简单模拟。

#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)的更多相关文章

  1. 【PAT甲级】1056 Mice and Rice (25 分)

    题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...

  2. pat 甲级 1056. Mice and Rice (25)

    1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...

  3. 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 ...

  4. 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 ...

  5. 1056. Mice and Rice (25)

    时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...

  6. 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 ...

  7. PAT甲题题解-1056. Mice and Rice (25)-模拟题

    有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...

  8. PAT (Advanced Level) 1113. Integer Set Partition (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT (Advanced Level) 1110. Complete Binary Tree (25)

    判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...

随机推荐

  1. hdu_4823_Energy Conversion

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4823 题意:中文题,很清楚,要注意的是乘起来会爆int 题解: #include<cstdio& ...

  2. nodejs 命令篇

    1.npm init // 生成package.json 2.npm install --save-dev gulp-jslint // 安装gulp-jslint模块,并把模块名和版本保存到pack ...

  3. docker Swarm 集群发现

    Node 发现 $swarm manage --discovery dockerhost01:,dockerhost02:,dockerhost03: -H= 文件发现 $swarm manage - ...

  4. React和动态网站接口的经济学

    来自: React and the economics of dynamic web interfaces 自从2000开始我就一直在做web开发,曾见过很多以各种库和框架的起起落落,这些库和框架作为 ...

  5. 微信支付WxpayAPI_php_v3(二)支付功能开发

    这里我没有开发openid和acessToken的获取,需要的请参考文档获取. 在阅读本教程之前请熟读微信支付的开发者文档. 直接开始[统一下单],在实际开发的项目中一般都有mvc分层的开发思想. 根 ...

  6. rownum使用方法

    rownum使用方法: .使用rownum子查询: rownum是一个总是从1开始的伪列,当查询条件rownum)时,不能从数据库查到记录,因此要 通过子查询解决:; 结果: SQL; R ID US ...

  7. 将undefault和null的数据转换成bool类型的数据 使用!!

    <script> var o={}; var a=null; console.info(!!o.name); </script> 输出false 此方法是将undefault和 ...

  8. 01_change_schema.sql

    set echo on feedback on spool ./log/01_change_schema.log -- -- schema change to v_idocdata_un -- -- ...

  9. 【中国剩余定理】 poj 1006

    生理周期  简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...

  10. Checking the Calendar

    Checking the Calendar time limit per test 1 second memory limit per test 256 megabytes input standar ...