简单模拟。

#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. INI文件的写入与读取

    INI文件的写入与读取 [节名]         '[]中的节名对应此API的第一参数 Name=内容      'Nmae对应此API的第二参数 API的第三参数是没有取到匹配内容时返回的字符串; ...

  2. Network view

    network view 组件用来在局域网之内去同步一个游戏物体的组件属性,只响应创建它的那个客户端事件

  3. Chapter 2 Open Book——22

    I dropped my head, letting my hair fall to conceal my face. 我低下了我的头,让我的头发垂下来隐藏我的脸. I was sure,though ...

  4. js 第一天

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  5. openwrt 中make的使用

    make 命令简单说明 make V=99 V=99表示输出详细的debug信息 make world 表示编译所有 make j=2 V=99 如是多核CPU,加j=2 选项理论上能加快编译速度 m ...

  6. HDU1686:Oulipo

    Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...

  7. 昨天上架出现问题,you binary is not optimized for iphone5.。。。。

    这个时候只需要加一个lanuch image 就可以了

  8. 给table加边框的两种方法

    <!DOCTYPE html><html><head><style>.a { border-spacing: 1px; background-color ...

  9. 使用WMware新建linux虚拟机

    使用WMware安装linux虚拟机的时候很多人搞不清楚使用什么适配器. 平时也看到很多误人子弟的观点,这里用事实说话. VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络 ...

  10. php 数组操作符

    1.数组操作符 数组运算符 例子 名称 结果 $a + $b 联合 $a 和 $b 的联合. $a == $b 相等 如果 $a 和 $b 具有相同的键/值对则为 TRUE. $a === $b 全等 ...