PAT a1056题解
来源:互联网 发布:数据库编程语言 编辑:程序博客网 时间:2024/06/05 03:41
#include <cstdio>#include <queue>using namespace std;const int maxn = 1010;struct mouse{int weight;int R;}mouse[maxn];int main(){int np, ng, order;scanf("%d%d", &np, &ng);for(int i = 0; i < np; i++){scanf("%d", &mouse[i].weight);}queue<int> q;for(int i = 0; i < np; i++){scanf("%d", &order);q.push(order);}int temp = np, group;while(q.size() != 1){if(temp % ng == 0) group = temp / ng;else group = temp / ng + 1;for(int i = 0; i < group; i++){int k = q.front();for(int j = 0; j < ng; j++){if(i * ng + j >= temp) break;int front = q.front();if(mouse[front].weight > mouse[k].weight){k = front;}mouse[front].R = group + 1;q.pop();}q.push(k);}temp = group;}mouse[q.front()].R = 1;for(int i = 0; i < np; i++){printf("%d", mouse[i].R);if(i < np -1) printf(" "); }return 0;}
阅读全文
1 0
- PAT a1056题解
- PAT-A1056
- PAT A1056 Mice an Rice
- 【PAT】A1056. Mice and Rice (25)
- pat-a1056. Mice and Rice (25)
- PAT A1056. Mice and Rice (25)
- PAT 1001-1010 题解
- PAT 1011-1020 题解
- PAT 1021-1030 题解
- PAT 1031-1040 题解
- PAT 1041-1050 题解
- PAT 1051-1060 题解
- PAT(basic level)题解
- PAT乙级题解
- PAT题解目录
- PAT甲级题解目录
- PAT乙级题解目录
- PAT甲级1001题解
- 电子书《程序原本》小述
- php 关联数组中随机的取出一个元素
- 关于网易公开课上南开数学文化的总结
- PAT a1055题解
- Service(远程服务)
- PAT a1056题解
- Matlab注释的几个方法
- excel入门,如何玩转excel,你早该这么玩Excel笔记11
- PAT a1058题解
- 学习tab标签的理解
- dijkstra求次短路径
- java中int、String的类型转换
- opencv-视频读取
- ARP协议