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只为一组, ...
随机推荐
- Squid代理服务器(一)——大家所用的游戏代理软件到底为何物?
一.代理服务器应用场景分析 想当年大学时候宿舍控制网速,苦了我们这帮魔兽党,一到晚上工会活动我们就得和全校上万名学生抢网速,作为坦克的我总是因为网速问题导致团灭,咱也是有自尊的人,一怒之下花300元办 ...
- 【重要的css属性学习】看了乙醇的文章,统计了几个高star前端框架下,Css属性出现最多的,这里学习记录一下
color background-color display margin-left border-color padding max-width margin-bottom width flex 待 ...
- 导出table为Excel
1.HTML <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=" ...
- 最小圆覆盖 [模板] BZOJ 1337&1336
题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入输出格式 输入格式: 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi& ...
- HLS-搭建Nginx流媒体服务器
Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个nginx的模块nginx-rtmp-module,组合在一起即可以搭建一个功能相对比较完善的流媒 ...
- sharepoint_study_4
描述:如何向sharepoint自定义列表,新建(编辑)页面的网站栏后,添加一个快捷方式? 如图示: 解决: 1.在SharePoint Designer中打开该自定义列表 2.右键NewForm.a ...
- HDU - 2203 KMP水题
循环移位的套路操作就是一份折开变两份 /*H E A D*/ void match(){ int n=strlen(T+1); int m=strlen(P+1); int j=0; rep(i,1, ...
- web 页面 验证码 实现
1. 前台页面代码: 页面刷新时会自动请求 ${pageContext.request.contextPath}/yanzheng?yz=&time=-1111 这个action <f ...
- Java中filter内处理重定向遇到的问题
这是在Java中filter内处理重定向遇到的问题.本意是写一个做URL rewrite 的filter,来重写URL,同时在处理登陆过程中要杀掉当前session,创建新session来代替. 1. ...
- dcoker machine
Docker Machine是一个安装和管理 Docker 的工具, 它有自己的命令行工具:docker-machine.Docker Machine简化了Docker的安装和远程管理, 不仅可以管理 ...