用结构体来存储变量,定义排序规则,对题目所讲的模拟一遍即可。没有什么很深入得内容
#include <bits/stdc++.h>
using namespace std;typedef struct
{int num;double sum;int count;
} Node;
bool cmp(Node node1, Node node2)
{if (node1.sum == node2.sum){if (node1.count == node2.count){return node1.num < node2.num;}return node1.count > node2.count; // 升序}return node1.sum > node2.sum; // 降序
}int main()
{int n;cin >> n;Node *nodes = new Node[n + 5];for (int i = 1; i <= n; i++){nodes[i].num = i;nodes[i].count = 0;nodes[i].sum = 0;}for (int i = 1; i <= n; i++){int t;cin >> t;for (int j = 1; j <= t; j++){int m, money;cin >> m >> money;nodes[i].sum -= money;nodes[m].sum += money;nodes[m].count++;}}sort(nodes + 1, nodes + n + 1, cmp);for (int i = 1; i <= n; i++){cout << nodes[i].num << " ";printf("%.2f\n", nodes[i].sum / 100);}
}