#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. 洛谷P2764 最小路径覆盖问题(最大流)

    传送门 先说做法:把原图拆成一个二分图,每一个点被拆成$A_i,B_i$,若原图中存在边$(u,v)$,则连边$(A_u,B_v)$,然后$S$对所有$A$连边,所有$B$对$T$连边,然后跑一个最大 ...

  2. 使用vue-cli脚手架搭建项目,保存编译时出现的代码检查错误(ESLint)

    一.问题 出现这么写错误是什么原因呢?相信很多小白都会像我一样,第一次接触时有点二丈和尚摸不着头脑.其实是在你用vue-cli脚手架构建项目时用了ESLint代码检查工具,如下图 那么什么是ESLin ...

  3. chmod变更文件或目录的权限

    chmod命令用来变更文件或目录的权限.在UNIX系统家族里,文件或目录权限的控制分别以读取.写入.执行3种一般权限来区分,另有3种特殊权限可供运用.用户可以使用chmod指令去变更文件与目录的权限, ...

  4. 黑马学习CSS之CSS模块化规范全部组成 CSS属性列表

  5. django基础知识之Response对象

    HttpResponse对象 在django.http模块中定义了HttpResponse对象的API HttpRequest对象由Django自动创建,HttpResponse对象由程序员创建 不调 ...

  6. C++_类入门5-智能指针模板类

    智能指针是行为类似于指针的类对象,但这种对象还有其他功能. 本节介绍三个可帮助管理动态内存分配的智能指针模板(auto_ptr.unique_ptr和shared_ptr). void remodel ...

  7. Windows 搭建ASP.NET Boilerplate项目开发环境

    1.本机安装对应版本的.net core 2.安装vs2017或以上版本 3.从ABP官网下载模板,我下载的是前后端分离的Angular模板 4.用vs2017分别打开前后端,还原Nuget包 5.前 ...

  8. ui-grid 中cellTemplate中click事件

    cellTemplate中使用的函数: 外部定义的函数:

  9. web 页面 验证码 实现

    1. 前台页面代码:  页面刷新时会自动请求 ${pageContext.request.contextPath}/yanzheng?yz=&time=-1111 这个action <f ...

  10. JS window,onload 与 $().read()

    JS:window.onload的使用介绍 .在body标签里面 .在JS语句调用 .同时调用多个函数 .JS调用多个函数 .自定义的函数多次调用 jquery $(document).ready() ...