1056 mice & rice(重做一次)

题目

This is a Question
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
#include <cstdio>
#include <queue>
#define MAX 1000
using namespace std;
struct mouse
{
int weight ;
int R;
}mouse[MAX];
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)//用来控制最后一组个数不等于ng的数据 ,可以用其他方式代替
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;
}

热评文章