题意:

输入两个正整数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. js数组和对象

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 09day vi命令详解

    vi有三种模式(互相切换) 1. 命令模式 2. 插入模式(编辑模式) 3. 低行模式 三种模式的切换方法: 使用技巧 vi 文件信息 i --- 进入编辑模式 esc --- 退出编辑模式 :wq ...

  3. Windows使用nmake和Makefile编译c++

    今天在本地看到一个lsd_1.6的源文件,不知道什么时候看LSD时下载的,里面只有一个Makefile和源文件. 想到在Linux下可以只用一个make命令就可以得到可执行程序,在Windows下是不 ...

  4. pgspider http fdw http 相关的几个配置参数

    http 请求时间配置 session 级别的 set http.timeout_msec = 10000; SELECT http_set_curlopt('CURLOPT_TIMEOUT', '1 ...

  5. 你了解getBoundingClientRect()?

    理解:getBoundingClientRect用于获取某个元素相对于视窗的位置集合.集合中有top, right, bottom, left等属性. 1.语法:这个方法没有参数. rectObjec ...

  6. 【HTTP与HTTPS的区别】

    目录 一.HTTP和HTTPS的基本概念 二.HTTP与HTTPS有何区别 三.HTTP与HTTPS的工作原理 四.HTTPS的优缺点 五.HTTP切换至HTTPS "超文本传输协议,即HT ...

  7. 记一道简单的re--BUUctf reverse1

    1.首先拖进ida里,看到了左面一百多function...还是shift+f12 查看敏感字符串吧 2.发现了这两个比较可疑的字符串,然后双击this is the right flag 进入到了他 ...

  8. 每日扫盲(五):RPC(Remote Procedure Call)

    作者:洪春涛链接:https://www.zhihu.com/question/25536695/answer/221638079来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  9. python实现获取电脑IP、主机名、Mac地址

    import socket import uuid # 获取主机名 hostname = socket.gethostname() #获取IP ip = socket.gethostbyname(ho ...

  10. 世界坐标转到UGUI坐标

    public static Vector3 WorldToUI(Camera camera,Vector3 pos){ CanvasScaler scaler = GameObject.Find(&q ...