AcWing 1561. PAT 评测
原题链接
简单
作者:
RainSure
,
2022-02-25 16:50:55
,
所有人可见
,
阅读 269
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 10010;
bool st[maxn];
int grades[10];
typedef struct node
{
int id;
int grade[10];
bool st[10];
int sum, cnt, rank;
bool operator < (const struct node &w) const{
if(sum != w.sum) return sum > w.sum;
}
}Node;
Node a[maxn];
int n, k, m;
bool cmp(Node a, Node b)
{
if(a.sum != b.sum) return a.sum > b.sum;
if(a.cnt != b.cnt) return a.cnt > b.cnt;
return a.id < b.id;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
cin >> n >> k >> m;
for(int i = 1; i <= k; i ++) cin >> grades[i];
for(int i = 1; i <= n; i ++) a[i].id = i;
for(int i = 0; i < m; i ++){
int id, idx, grade; cin >> id >> idx >> grade;
if(grade >= 0) {
a[id].grade[idx] = max(a[id].grade[idx], grade);
st[id] = true;
}
a[id].st[idx] = true;
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= k; j ++){
a[i].sum += a[i].grade[j];
a[i].cnt += a[i].grade[j] == grades[j];
}
}
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i ++){
if(i == 1 || a[i].sum != a[i - 1].sum) a[i].rank = i;
else a[i].rank = a[i - 1].rank;
}
for(int i = 1; i <= n; i ++){
if(st[a[i].id]){
printf("%d %05d %d", a[i].rank, a[i].id, a[i].sum);
for(int j = 1; j <= k; j ++){
if(a[i].st[j]) printf(" %d", a[i].grade[j]);
else printf(" -");
}
puts("");
}
}
return 0;
}