1056 Mice and Rice (25分)
参考
题目读了好久都没读明白。。。看了上方链接的解释才懂什么意思,感觉好绕。。。
第二行为0~n-1的老鼠重量,第三行为合并的次序序号,最后按0到n-1输出排行
排行为1 2 2 4形式

#include<iostream>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
struct node {int v, id, rank;
};
bool cmp(node a, node b) { return a.v > b.v; }
int main() {int n, m, t;cin >> n >> m;vector<node> temp(n), a;queue<node> q;for (int i = 0; i < n; i++) {cin >> temp[i].v;temp[i].id = i;}for (int i = 0; i < n; i++) {cin >> t;q.push(temp[t]);}int cnt = 1, sum = q.size();while (q.size() > 1) {sum=ceil((float)sum / (float)m);//sum为下一波元素个数,也是当前可分的组数int rank =sum  + 1;//当前被淘汰的排行为组数+1vector<node> p;for (int i = 0; i < sum;i++) {t = m;while (q.size()&&t--) {a.push_back(q.front());q.pop();}sort(a.begin(), a.end(),cmp);p.push_back(a[0]);for (int j = 1; j < a.size(); j++) {temp[a[j].id].rank = rank;}a.clear();}for (int i = 0; i < p.size(); i++) {q.push(p[i]);}p.clear();}temp[q.front().id].rank = 1;for (int i = 0; i < n; i++) {if (i) { cout << ' '; }cout << temp[i].rank;}return 0;
}

1056 Mice and Rice (25分)相关推荐

  1. 1056 Mice and Rice (25 分)【难度: 一般 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805419468242944 这里是用队列模拟. #include< ...

  2. PTA 1056 Mice and Rice (25分)

    题面:自己读,甲级题面自己读; 神奇的做法 一开始以为就是一个堆栈的模拟 没考虑到复杂度写到一半发现 查找中位数的复杂度实在是太高了O(nnlog) 那不就裂开了嘛 后来想到 中位数 可以单独维护一个 ...

  3. 1056. Mice and Rice (25)

    1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...

  4. A1056 Mice and Rice (25 分| queue用法,附详细注释,逻辑分析)

    写在前面 思路分析 np为老鼠数量, ng为每组最多g个老鼠. 先给出np个老鼠重量,再给出老鼠初始顺序 每ng个老鼠分为1组,对于每组老鼠,选出最重的那个,晋级下1轮比赛,然后依次再以np个老鼠1组 ...

  5. 1056 Mice and Rice (25 point(s))

    Matter: 1.很难受,这个想了好长时间,发现没读懂题目.second line 是每个老鼠的质量(W​i​​ is the weight of the i-th mouse),third lin ...

  6. PAT 甲级 1056 Mice and Rice

    1056 Mice and Rice 题目大意:给出老鼠的数量和每组的人数,将老鼠分成若干组(多下来不够每组人数的算作一组),第二行给出每只老鼠最终的重量,第三行给出分组顺序 思路:记录每轮获胜的选手 ...

  7. PAT 1056 Mice and Rice

    for the sake of simplicity:为了简单起见 permutation:排序 Np programmers:the number of programmers(程序员的数量) Ng ...

  8. PAT甲级1056 Mice and Rice:[C++题解]模拟、排名

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 本题采用vector存每只老鼠,为什么用vector,因为每过一轮剩余老鼠数量是动态变化的. 每组中未选出的选手排名相同,排名等于进 ...

  9. 1056 Mice and Rice

    题目 题意: n为老鼠的数量,每组最多m个老鼠.先给出n个老鼠的重量,再给出老鼠的初始顺序(第i名的老鼠是第j号,j从0开始).每m个老鼠分为一组,对于每组老鼠,选出最重的那个,晋级下一轮比赛,然后依 ...

最新文章

  1. VirtualBox6.0中CentOS7.6 网络配置
  2. Python实例浅谈之五Python守护进程和脚本单例运行
  3. GPU — 体系结构
  4. html打包成app的缓存问题,webpack 独立打包与缓存处理
  5. 非root安装php nginx,非root用户安装nginx
  6. jquery插件:图片截取工具jquery.imagecropper.js
  7. aws rds监控慢sql_AWS RDS SQL Server中的高级Windows身份验证配置
  8. 爬虫中无头浏览器如何选择
  9. 阿里云主机修改操作系统 详细步骤
  10. org.postgresql.util.PSQLException: 不支援 10 验证类型
  11. 克鲁斯卡尔(Kruskal)算法(严蔚敏C语言)
  12. Win10下使用nvm安装多个版本node.js
  13. PHP中常用数学、日期、字符串函数
  14. ideaVim 使用总结
  15. 长为一名JAVA架构师2017-10-16 2
  16. 陳三甲网络笔记:赚钱路上,一些人生思考(连载四)
  17. 云终端和瘦客户机的区别
  18. Axure怎样制作内部框架
  19. Kaggle数据集猫狗分类(Pytorch+ResNet34预训练)99%以上正确率
  20. 【踩坑日记】vue项目ie打不开报错SCRIPT1006:缺少‘)‘

热门文章

  1. 互联网之父温顿·瑟夫今日访华
  2. android 手电筒服务,Android手电筒案例
  3. 2022-10-11(一、远程命令执行和系统命令执行)
  4. 怎么理解cpu load?
  5. 传奇3服务器.gen文件,传奇3刺客4职业gsp国际版+教程+客户端
  6. JAVA 环境配置JDK
  7. qt 三方源码 画饼图_[源码和文档分享]基于VC++和QT实现的图的可视化工具
  8. vue scroll 监听,点击按钮自动滚动到相应的信息展示
  9. matlab的符号变量sym,syms
  10. 数据库学习之sql语句基础