PAT 1056 Mice and Rice
#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的更多相关文章
- PAT 1056 Mice and Rice[难][不理解]
1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...
- pat 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- 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 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)
时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...
- 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 ...
- PAT甲题题解-1056. Mice and Rice (25)-模拟题
有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...
- PAT (Advanced Level) 1056. Mice and Rice (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- 【PAT甲级】1056 Mice and Rice (25 分)
题意: 输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序.输出它们的名次.(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组, ...
随机推荐
- DOS远程桌面连接命令[佚名]
DOS远程桌面连接命令 mstsc /v: 192.168.1.250 /console cmd 运行 command 删除文件 rd 文件名/S 创建文件 MD 文件名 net user admin ...
- Ubuntu16.04搭建各种开发环境的IDE: QT5 , CodeBlocks ,eclipse-cdt, PyCharm
搭建Ubuntu下C/C++以及Python的集成开发环境,采用双系统(Win7+Ubuntu)的Ubuntu16.04-LTS系统, 关于双系统的搭建可以参考下面博客(图文十分详细):https:/ ...
- 获取表单提交的数据getParameter()方法
请求对象:request public String getParameter(String name); 通过request的getParameter(String name)方法获取 表单里面的n ...
- linux上的那些查找的命令
由于工作的需要,少不得要在linux系统上查找各种各样的文件,关于在linux查找的命令有不少,这里小小的总结下. 简单介绍下各个命令的用途: find:实际搜索硬盘查询文件名称: whereis:查 ...
- windows下Idea结合maven开发spark和本地调试
本人的开发环境: 1.虚拟机centos 6.5 2.jdk 1.8 3.spark2.2.0 4.scala 2.11.8 5.maven 3.5.2 在开发和搭环境时必须注意版本兼容的问题 ...
- Axure 原型图
Axure RP 9最新版软件及汉化包下载 https://www.axure.com.cn/78629/ 点击下载 lang语言包放在根目录即可 Axure各种版本注册码 | 最新Axure R ...
- Android 基于TCP多线程通信实现群聊天的功能
1.TCP多线程原理图 2.实现方法 (1)服务器端 (2)客户端 3.java后台代码 主界面 package com.lucky.test50socket2; import android.ann ...
- abp学习资料
参考: https://www.jianshu.com/p/a6e9ace79345
- P3345 [ZJOI2015]幻想乡战略游戏
传送门 考虑先随便找一个点作为根,然后再慢慢移动根,这样一步步走到最优的点 设 $sum[x]$ 表示节点 $x$ 的子树的军队数,$len(x,y)$ 表示 $x,y$ 之间边的长度 那么对于根节点 ...
- HDU 6351 (带技巧的暴力)
题意:给定一个数,和一个最多交换次数k,问在不超过k次操作的情况,问可以得到的最大值和最小值是多少? 个人解题的艰辛路程 , 开始是想到了暴力枚举的可能 , 打出来发现在判断枚举的数组与原来数组交换了 ...