-
Notifications
You must be signed in to change notification settings - Fork 0
/
1056.cpp
82 lines (70 loc) · 1.56 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = 1010;
struct Mice{
int num;
int weight;
int rank;
}mice[maxn];
int main(){
int np, ng;
scanf("%d %d", &np, &ng);
for(int i = 0; i < np; i++){
scanf("%d", &mice[i].weight);
mice[i].num = i;
}
queue<Mice> q[maxn];
for(int i = 0; i < np; i++){
int order;
scanf("%d", &order);
q[0].push(mice[order]);
}
//计算轮数
int turns = 0;
int p = np;
while(p != 1){
if(p % ng == 0){
p = p / ng;
turns++;
}
else{
p = p / ng + 1;
turns++;
}
}
int r = np;
for(int i = 0; i < turns; i++){
int rank;
if(r % ng == 0){
rank = r / ng + 1;
r = r / ng;
}
else{
rank = r / ng + 2;
r = r / ng + 1;
}
while(!q[i].empty()){
int max = -1, max_num;
Mice temp;
for(int j = 0; j < ng && !q[i].empty(); j++){
temp = q[i].front();
q[i].pop();
mice[temp.num].rank = rank;
if(temp.weight > max){
max = temp.weight;
max_num = temp.num;
}
}
q[i + 1].push(mice[max_num]);
}
}
mice[q[turns].front().num].rank = 1;
for(int i = 0; i < np; i++){
printf("%d", mice[i].rank);
if(i != np - 1){
printf(" ");
}
}
return 0;
}