排序题
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 |
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <map> using
namespace std; const
int N = 100005; int
score[10]; struct
Node { int
id; int
problem; int
get; }person[N]; struct
ANS { int
rank; int
id; int
total; int
get[6]; bool
flag; int
perfect; }ans[10005]; int
cmp1( const
ANS &a, const
ANS &b) { if
(a.total != b.total) return
a.total > b.total; if
(a.perfect != b.perfect) return
a.perfect > b.perfect; else
return a.id < b.id; } void
get_total( int
n, int
m, int
k) { int
i = 0, j = 0; for
(i = 1; i <= n; i++) { for
(j = 1; j <= m; j++) ans[i].get[j] = -2; ans[i].flag = 0; ans[i].perfect = 0; } for
(i = 0; i < k; i++) { int
idx = person[i].id; int
pro = person[i].problem; int
soc = person[i].get; if
(soc == score[pro] && ans[idx].get[pro] != soc) ans[idx].perfect++; if
(soc > ans[idx].get[pro]) ans[idx].get[pro] = soc; } for
(i = 1; i <= n; i++) { int
sum = 0; for
(j = 1; j <= m; j++) { if
(ans[i].get[j] >= 0) { ans[i].flag = 1; sum += ans[i].get[j]; } } ans[i].total = sum; ans[i].id = i; } } void
get_rank( int
n) { int
rank = 1; int
i = 0; ans[1].rank = 1; for
(i = 2; i <= n; i++) { if
(ans[i].total == ans[i - 1].total) ans[i].rank = ans[i - 1].rank; else
ans[i].rank = i; } } void
print_info( int
n, int
m) { for
( int i = 1; i <= n; i++) { if
(ans[i].flag == 0) continue ; printf ( "%d %05d %d" , ans[i].rank, ans[i].id, ans[i].total); for
( int j = 1; j <= m; j++) { if
(ans[i].get[j] == -2) printf ( " -" ); else
if (ans[i].get[j] == -1) printf ( " 0" ); else printf ( " %d" , ans[i].get[j]); } printf ( "\n" ); } } int
main() { int
n, m, k; int
i; while
( scanf ( "%d%d%d" , &n, &m, &k) != EOF) { for
(i = 1; i <= m; i++) scanf ( "%d" , &score[i]); for
(i = 0; i < k; i++) scanf ( "%d%d%d" , &person[i].id, &person[i].problem, &person[i].get); //sort(person, person, cmp); get_total(n, m, k); sort(ans + 1, ans + n + 1, cmp1); get_rank(n); print_info(n, m); } return
0; } |
1075 PAT Judge (25),布布扣,bubuko.com
原文:http://www.cnblogs.com/echobfy/p/3576805.html