题意:

输入两个正整数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. java位移运算符|And&,操作二进制

    在java中 逻辑运算符有四种:&  ,  |,  &&,  || &: 如果第一个条件是fasle,还会判断第二个条件,只要有一个条件不满足,结果就返回false; ...

  2. grep Or And 操作

    grep or 操作符 使用 \| 如果不使用grep命令的任何选项,可以通过使用 '|' 来分割多个pattern,以此实现OR的操作. grep 'pattern1\|pattern2' file ...

  3. rabbitmq快速安装(实测有效)(新版)

    rabbitMq的快速安装和使用在第二部分,第一部分就看个热闹,第二部分直接可以完成环境的搭建 如果需要资料的话可以直接来 这里 进行下载 第一部分 http://www.cnerlang.com/r ...

  4. python如何将自己写的代码打包供他人使用

    背景: 利用setuptools来实现,所以先安装setuptools,其实Python2.7.9及之后的版本都自带安装setuptools了,无需在另外安装 如果没有安装setuptools的直接下 ...

  5. VUE常用写法

    v-for: v-for ='item,key of data' v-for ='item,index in data'     @click='' @click='pop.show=false'   ...

  6. 微服务介绍和springCloud组件

      微服务架构模式是:将整个web服务 组织成一系列小的web 服务,这些小的web服务可以进行独立的编译和部署,并通过各自暴露的API接口 进行相互通信,他们相互协作,作为一个整体,为客户提供服务功 ...

  7. 【Python collections】

    目录 namedtuple deque Counter OrderedDict defaultdict "在内置数据类型(dict.list.set.tuple)的基础上,collectio ...

  8. Eclipse导入git上的maven web项目 以及部署成功运行

      在公司开发的时候都是用maven 以及git环境 开发的环境,那么我们初学者怎么将公司的项目成功导入到eclipse中,并且成功运行那???下面的教程就可以告诉大家~ (ps:第二步可能是大家会遇 ...

  9. 基于Aspectj表达式配置的Spring AOP

    AOP(Aspect-Oriented Programming, 面向切面编程):是一种新的方法论, 是对传统OOP(Object-Oriented Programming, 面向对象编程)的补充. ...

  10. Go 开发关键技术指南 | Go 面向失败编程 (内含超全知识大图)

    作者 | 杨成立(忘篱) 阿里巴巴高级技术专家 关注"阿里巴巴云原生"公众号,回复 Go 即可查看清晰知识大图! 导读:从问题本身出发,不局限于 Go 语言,探讨服务器中常常遇到的 ...