题目链接:
L2-009 抢红包 (25分)
思路:
自定义排序即可
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 12345;
struct per {
int no, ans, cnt;
bool operator < (const per & a) const {
if(ans != a.ans) return ans > a.ans;
return cnt == a.cnt ? no < a.no : cnt > a.cnt;
}
}a[maxn];
int main() {
#ifdef MyTest
freopen("Sakura.txt", "r", stdin);
#endif
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) a[i] = per {i, 0, 0};
for(int i = 1; i <= n; ++i) {
int k;
scanf("%d", &k);
while(k--) {
int no, p;
scanf("%d %d", &no, &p);
a[i].ans -= p;
a[no].ans += p;
a[no].cnt++;
}
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; ++i) {
printf("%d %.2f
", a[i].no, a[i].ans / 100.0);
}
return 0;
}