1 条题解

  • 1
    @ 2025-1-25 23:10:53

    看清总评价的计算公式后利用 structsort 排序即可。

    为了避免精度误差,建议按 k=(2m+n)tk=(2m+n)t(将原来的公式除以 0.030.03)计算总评价,此时需要使用 long long。(当然了,直接使用 doublelong 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;
    }
    
    • 1

    信息

    ID
    146
    时间
    1000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    26
    已通过
    8
    上传者