https://pintia.cn/problem-sets/994805046380707840/problems/994805066890854400
AC代碼:
#include<bits/stdc++.h>
using namespace std;
struct per {
? ? int id;
? ? int p;
? ? int cnt;
} h[10100];
bool cmp(per a, per b) {
? ? if(a.p == b.p) {
? ? ? ? if(a.cnt == b.cnt) {
? ? ? ? ? ? return a.id < b.id;
? ? ? ? } else {
? ? ? ? ? ? return a.cnt > b.cnt;
? ? ? ? }
? ? } else
? ? ? ? return a.p > b.p;
}
int main() {
? ? int k;
? ? for(int i = 0; i < 10100; i++) {
? ? ? ? h[i].id = i;
? ? ? ? h[i].p = 0;
? ? ? ? h[i].cnt = 0;
? ? }
? ? cin >> k;
? ? for(int i = 1; i <= k; i++) {
? ? ? ? int m;
? ? ? ? cin >> m;
? ? ? ? for(int j = 0; j < m; j++) {
? ? ? ? ? ? int id, x;
? ? ? ? ? ? cin >> id >> x;
? ? ? ? ? ? h[id].p += x;
? ? ? ? ? ? h[i].p -= x;
? ? ? ? ? ? h[id].cnt++;
? ? ? ? }
? ? }
? ? sort(h + 1, h + k + 1, cmp);
? ? for(int i = 1; i <= k; i++) {
? ? ? ? cout << h[i].id << ' ';
? ? ? ? cout << setiosflags(ios::fixed);
? ? ? ? cout << setprecision(2);
? ? ? ? cout << h[i].p / 100.0 << endl;
? ? }
}