输入样例:
10
3 2 22 10 58 8 125
5 1 345 3 211 5 233 7 13 8 101
1 7 8800
2 1 1000 2 1000
2 4 250 10 320
6 5 11 9 22 8 33 7 44 10 55 4 2
1 3 8800
2 1 23 2 123
1 8 250
4 2 121 4 516 7 112 9 10
输出样例:
1 11.63
2 3.63
8 3.63
3 2.11
7 1.69
6 -1.67
9 -2.18
10 -3.26
5 -3.26
4 -12.32
简单题,为了防止有的小朋友代码有的地方有纰漏先写一下题解,我记得我当时第一次做这个题的时候还是出了很多问题的,这次一次过了,感觉还是有点开心。
#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 10;
struct node{int id, n, m;node(int a = 0, int b = 0, int c = 0){id = a, n = b, m = c;}bool operator < (const node & t) const{if(m != t.m) return m > t.m;else if(n != t.n) return n > t.n;else return id < t.id;}
}P[N];
int main(){int n, id, m;cin>>n;int xx = n;int k;for(int i = 1; i <= n; i++){cin>>k;int summ = 0;while(k--){cin>>id>>m;summ += m;P[id].id = id;P[id].m += m;P[id].n ++;}P[i].id = i;P[i].m -= summ;}sort(P + 1, P + xx + 1);for(int i = 1; i <= xx; i ++){double mm = P[i].m * 1.0 / 100;cout<<P[i].id<<" ";printf("%.2f", mm);if(i != xx ) cout<<endl;}return 0;
}