题意:

输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序。输出它们的名次。(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组,每组只能有一个胜者,其他老鼠排名均为这一轮胜者数量+1)

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[],b[];
int num;
int ans[];
int c[],d[];
pair<int,int>e[];
int flag;
bool vis[];
void contest(){
int cnt=;
int round=;
int no=;
for(int i=;i<=num;++i){
c[++cnt]=b[i];
if(cnt==m||i==num){
++round;
int mx=a[c[]],pos=c[];
for(int j=;j<=cnt;++j)
if(a[c[j]]>mx){
mx=a[c[j]];
pos=c[j];
}
for(int j=;j<=cnt;++j)
if(c[j]==pos)
d[++no]=c[j];
else
vis[c[j]]=;
cnt=;
}
}
for(int i=;i<=num;++i)
if(!ans[b[i]]&&vis[b[i]])
ans[b[i]]=round+;
if(round==){
ans[d[]]=;
flag=;
}
for(int i=;i<=no;++i)
b[i]=d[i];
num=no;
no=;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=;i<=n;++i)
cin>>a[i];
for(int i=;i<=n;++i){
cin>>b[i];
++b[i];
}
num=n;
while(!flag)
contest();
cout<<ans[];
for(int i=;i<=n;++i)
cout<<" "<<ans[i];
return ;
}

【PAT甲级】1056 Mice and Rice (25 分)的更多相关文章

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

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

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

  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. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

  7. PAT甲级——A1056 Mice and Rice

    Mice and Rice is the name of a programming contest in which each programmer must write a piece of co ...

  8. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  9. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

随机推荐

  1. jmeter的使用---控制器

    1.如果(If)控制器.Switch Controller if控制语句,判断字段是否存在,或者符合,执行不同的逻辑 2.简单控制器 一次进件流程,需要不同模块的数据,例如登陆,提交个人信息,信用认证 ...

  2. expdp定时备份

    1.创建用户所需的永久表空间和临时表空间 create tablespace tbs_hankey_dat datafile '/opt/oracle/oradata/tbs_hankey.dbf' ...

  3. vue中的金额格式0.00 和 后台返回时间格式带T调整正常格式

    <template> <div class="consumption"> <p>{{payTime|Time}}</p> <p ...

  4. C# 委托实例实现的多种类型

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. tableSizeFor()函数在java8和Java13的差别

    java8 static final int tableSizeFor(int cap) { int n = cap - 1; n |= n >>> 1; n |= n >&g ...

  6. 查询数据操作:limit

    1.作用: 在查看数据时用于限制获得的记录数量,一般放在最后. 2.语法: limit offset,row_count; 解析: offset:偏移量,索引值默认从0开始,可以省略 row_coun ...

  7. iOS 组件化开发之使用CocoaPod制作自己的远程私有库

    随着应用需求逐步迭代,应用的代码体积将会越来越大,为了更好的管理应用工程,我们开始借助CocoaPods版本管理工具对原有应用工程进行拆分.但是仅仅完成代码拆分还不足以解决业务之间的代码耦合,为了更好 ...

  8. 刷题10. Regular Expression Matching

    一.题目说明 这个题目是10. Regular Expression Matching,乍一看不是很难. 但我实现提交后,总是报错.不得已查看了答案. 二.我的做法 我的实现,最大的问题在于对.*的处 ...

  9. Navicat Premium 12安装、激活

    Navicat Premium 12安装 Navicat Premium 12激活

  10. php 基础 字符型转换整形

    示例: 可以得出规律:以有效数字开头的,取有效数字.以非有效数字开头的都转换为0: