-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1056.cpp
61 lines (58 loc) · 1.23 KB
/
1056.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// 1056.cpp
// 算法
//
// Created by 王怡凡 on 2017/3/27.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#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);
int i;
for(i=0;i<np;i++) {
scanf("%d",&mouse[i].weight);
}
queue<int> q;
for(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(i=0;i<group;i++) {
int j,k = q.front();
for(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(i=0;i<np;i++) {
printf("%d",mouse[i].r);
if(i<np-1) {
printf(" ");
}
}
return 0;
}