- P104's solution
P104's Solution
- 2025-9-4 21:59:46 @
看清总评价的计算公式后利用 struct
和 sort
排序即可。
为了避免精度误差,建议按 (将原来的公式除以 )计算总评价,此时需要使用 long long
。(当然了,直接使用 double
或 long double
也是一个不错的选择。)
#include <bits/stdc++.h>
using namespace std;
const int A = 20 + 2;
struct Team
{
string b;
int m;
int n;
int t;
long long k;
};
Team team[A];
bool cmp(Team x, Team y)
{
return x.k > y.k;
}
int main()
{
freopen("football.in", "r", stdin);
freopen("football.out", "w", stdout);
int T;
cin >> T;
while (T--)
{
int a;
cin >> a;
for (int i = 1; i <= a; i++)
{
cin >> team[i].b >> team[i].m >> team[i].n >> team[i].t;
team[i].k = 1ll * team[i].t * (2ll * team[i].m + 1ll * team[i].n);
}
sort(team + 1, team + a + 1, cmp);
for (int i = 1; i <= a; i++)
{
cout << team[i].b;
if (i != a) cout << ' ';
}
cout << endl;
}
return 0;
}