#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <list> using namespace std; list<int>::iterator group_pick(list<int> &player, list<int>::iterator &cur, int group_size, vector<int> &W) {
int wmax = INT_MIN;
list<int>::iterator ret = player.end();
int cnt = group_size;
//printf("check group:\n\t");
while (cur != player.end() && cnt > ) {
--cnt;
//printf(" %d(%d)", *cur, W[*cur]);
if (W[*cur] >= wmax) {
wmax = W[*cur];
ret = cur;
}
cur++;
}
//printf("\n");
return ret;
} int main() { int N = , G = ;
scanf("%d%d", &N, &G); if (N < ) return ; vector<int> W(N, );
vector<int> R(N, );
vector<int> L;
list<int> P; for (int i=; i<N; i++) {
scanf("%d", &W[i]);
}
for (int i=; i<N; i++) {
int t = ;
scanf("%d", &t);
P.push_back(t);
} int level = ;
int level_cnt = ; list<int> tmp;
auto cur = P.begin();
// number of elements in P should be larger than 1 to perform reduce processing
while (G > && ++(cur = P.begin()) != P.end()) {
tmp.clear();
auto cur = P.begin();
while (cur != P.end()) {
list<int>::iterator fat = group_pick(P, cur, G, W);
//printf("pick %d\n", *fat);
tmp.splice(tmp.end(), tmp, fat);
} swap(tmp, P);
auto iter = tmp.begin();
while (iter != tmp.end()) {
R[*(iter++)] = level;
level_cnt++;
}
L.push_back(level_cnt);
level_cnt = ;
level++;
}
// now there must be only one element in P, the final winner
L.push_back();
R[P.front()] = level;
int sum = ;
for (int i=L.size() - ; i>=; i--) {
//printf("level cnt: %d\n", L[i]);
int next_sum = sum + L[i];
L[i] = sum + ;
sum = next_sum;
} int len = R.size();
printf("%d", L[R[]]);
for (int i=; i<len; i++) {
printf(" %d", L[R[i]]);
}
return ;
}

有点烦啊

PAT 1056 Mice and Rice的更多相关文章

  1. PAT 1056 Mice and Rice[难][不理解]

    1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...

  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) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  9. 【PAT甲级】1056 Mice and Rice (25 分)

    题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...

随机推荐

  1. 洛谷P3254 圆桌问题(最大流)

    传送门 一道良心啊……没那么多麻烦了…… 从$S$向所有单位连边,容量为单位人数,从所有桌子向$T$连边,容量为桌子能坐的人数,从每一个单位向所有桌子连边,容量为$1$,然后跑一个最大流,看一看$S$ ...

  2. 数据解析之xpath

    一.环境安装 下载lxml pip install lxml 二.使用 XPath 使用路径表达式来选取 XML 文档中的节点或节点集.节点是通过沿着路径 (path) 或者步 (steps) 来选取 ...

  3. 跟我一起读postgresql源码(三)——Rewrite(查询重写模块)

    上一篇博文我们阅读了postgresql中查询分析模块的源码.查询分析模块对前台送来的命令进行词法分析.语法分析和语义分析后获得对应的查询树(Query).在获得查询树之后,程序开始对查询树进行查询重 ...

  4. vue可视化图表 基于Echarts封装好的v-charts简介

    **vue可视化图表 基于Echarts封装好的v-charts** 近期公司又一个新的需求,要做一个订单和销售额统计的项目,需要用到可视化图表来更直观的展示数据.首先我想到的是Echarts,众所周 ...

  5. 《条目十六》如何将vector和string的数据传给遗留的API

    <条目十六>如何将vector和string的数据传给遗留的API 优秀的代码是可以延续的,所以并非所有的代码都是重构的,而且有时候重构会对整个系统影响较大,投入巨大,得不偿失.然而,也不 ...

  6. [Maven]Codehaus的Maven Repository地址

    In ~/.m2/settings.xml you can update the URL to be used for specific repositories. For example: < ...

  7. 使用Swagger生成简单接口文档

    使用swagger通过简单的配置可以生成简单的接口文档: 依赖包: // Swagger2 compile 'io.springfox:springfox-swagger2:2.8.0' compil ...

  8. 洛谷 P2495 [SDOI2011]消耗战(虚树,dp)

    题面 洛谷 题解 虚树+dp 关于虚树 了解一下 具体实现 inline void insert(int x) { if (top == 1) {s[++top] = x; return ;} int ...

  9. centos7安装nslookup工具、ntp工具

    2018-12-13 centos7安装nslookup工具 yum install bind-utils -y DNS解析localhost到本机 # .检测 [root@node2 ~]# nsl ...

  10. PIE SDK矢量分级渲染

    1. 功能简介 分级渲染是矢量的一种数据表达方式.通过选取一个字段,并根据实际需要对字段的数据进行分级,并对每一级设置不同的符号,已达到区分显示的效果. 2. 功能实现说明 2.1. 实现思路及原理说 ...