【PAT甲级】1056 Mice and Rice (25 分)
题意:
输入两个正整数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 分)的更多相关文章
- 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 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- 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分)队列
1.27刷题2 Mice and Rice is the name of a programming contest in which each programmer must write a pie ...
- 1056. Mice and Rice (25)
时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- 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 ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
随机推荐
- 使用Id访问table对象,使用Id访问Input对象
先看例子(好吧 无意中发现 可以通过Id访问DOM元素,如div) <!DOCTYPE html> <html> <head> <meta cha ...
- 力扣MYSQL练习
176编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . select IFNULL((SELECT distinct salary from employee or ...
- DataGridView 更改Header样式
'必须先设置 EnableHeadersVisualStyles 属性 才能设置Header颜色dgv.EnableHeadersVisualStyles = Falsedgv.ColumnHeade ...
- bugku 好多压缩包
https://www.cnblogs.com/WangAoBo/p/6951160.html
- docker 报错 docker: Error response from daemon: driver failed....iptables failed:
现象: [root@localhost test]# docker run --name postgres1 -e POSTGRES_PASSWORD=password -p : -d postgre ...
- NAT ALG原理与应用
1 NAT ALG简介 普通NAT实现了对UDP或TCP报文头中的的IP地址及端口转换功能,但对应用层数据载荷中的字段无能为力,在许多应用层协议中,比如多媒体协议(H.323.SIP等).FTP.S ...
- 设置idea的快捷键组合 设置为默认
ubuntu中,idea的快捷键组合 为 “Default for GNOME”,和windows中不一样了,需要修改为“Default”:
- Ansible - playbook - 概要
概述 简单描述 ansible playbook 1. playbook 概述 ansible 的 "脚本" 场景 ansible 单条命令, 执行一个操作 问题 如果执行多个操作 ...
- php 移动操作数组函数
下面的几个主要是移动数组指针和压入弹出数组元素的和个函数. 函数 功能 array_shift 弹出数组中的第一个元素 array_unshift 在数组的开始处压入元素 array_push 向数组 ...
- winform 多个datagridview 之间同步滚动
1.添加Scroll事件 2.注意需判断数据长度,避免溢出 private void dgYY_Scroll(object sender, ScrollEventArgs e) { ) { dgFee ...