-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMice and Rice.cpp
69 lines (65 loc) · 1.27 KB
/
Mice and Rice.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
#include <algorithm>
#include <iostream>
int temp[1010];
struct node
{
int weight, order, rank = -1;
} a[1010];
node s[1010];
bool cmp(node a, node b)
{
return a.order < b.order;
}
bool cmp2(node a, node b)
{
return a.weight > b.weight;
}
int main()
{
int n, k;
std::cin >> n >> k;
for (int i = 0; i < n; i++)
{
std::cin >> temp[i];
}
for (int i = 0; i < n; i++)
{
int order;
std::cin >> order;
a[i].weight = temp[order];
a[i].order = order;
}
while (k > n)
{
int count = 0;
int num = 0;
for (int i = 0; i < n; i++)
{
if (a[i].rank == -1)
s[count++] = a[i];
if (count == k)
{
std::sort(s, s + count, cmp2);
s[0].rank = 0;
num++;
count = 0;
}
}
for (int i = 0; i < n; i++)
{
if (a[i].rank == -1)
a[i].rank = num + 1;
if (a[i].rank == 0)
a[i].rank = -1;
}
k = k * k;
}
std::sort(a, a + n, cmp);
for (int i = 0; i < n; i++)
{
std::cout << a[i].rank;
if (i != n - 1)
std::cout << " ";
}
return 0;
}