-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1056.cpp
68 lines (68 loc) · 1.21 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
#include<stdio.h>
#include<vector>
using namespace std;
#define DEBUG
class Pro{
public:
int w;
int p;
};
int main()
{
int np,ng;
scanf("%d%d",&np,&ng);
Pro programmers[1001];
int i;
for(i=0;i<np;i++)
scanf("%d",&(programmers[i].w));
vector<int> pv;
vector<int> winv;
vector<int> losev;
for(i=0;i<np;i++)
{
int t;
scanf("%d",&t);
pv.push_back(t);
}
while(pv.size()>1)
{
#ifdef DEBUG
printf("now pv.size: %d\n",pv.size());
#endif
winv.clear();
losev.clear();
for(i=0;i<pv.size();i+=ng)
{
int maxIndex=pv[i];
for(int j=i+1;j<i+ng && j<pv.size();j++)
if(programmers[pv[j]].w>programmers[maxIndex].w)
{
#ifdef DEBUG
printf("change maxIndex from %d to %d\n",maxIndex,pv[j]);
#endif
maxIndex=pv[j];
}
#ifdef DEBUG
printf("find a winner: %d\n",maxIndex);
#endif
winv.push_back(maxIndex);
for(int j=i;j<i+ng && j<pv.size();j++)
if(pv[j]!=maxIndex)
{
#ifdef DEBUG
printf("find a loser: %d\n",pv[j]);
#endif
losev.push_back(pv[j]);
}
}
int rank=winv.size()+1;
for(int j=0;j<losev.size();j++)
programmers[losev[j]].p=rank;
pv=winv;
}
programmers[pv[0]].p=1;
printf("%d",programmers[0].p);
for(i=1;i<np;i++)
printf(" %d",programmers[i].p);
return 0;
}