2 条题解

  • 0
    @ 2026-4-4 12:12:39

    直接按公式排就可以了。

    AC code:

    #include <bits/stdc++.h>
    using namespace std;
    
    struct Node {
        string name;
        double k;
    };
    
    bool cmp(const Node& a, const Node& b) {
        return a.k > b.k;
    }
    
    int main() {
        freopen("football.in", "r", stdin);
        freopen("football.out", "w", stdout);
        int T;
        cin >> T;
        while (T--) {
            int a;
            cin >> a;
            vector<Node> Nodes(a);
            for (int i = 0; i < a; i++) {
                string name;
                long long m, n;
                int t;
                cin >> name >> m >> n >> t;
                double k = (0.6 * m + 0.3 * n) * 0.1 * t;
                Nodes[i].name = name, Nodes[i].k = k;
            }
            sort(Nodes.begin(), Nodes.end(), cmp);
            for (int i = 0; i < a; i++) {
                if (i > 0) {
                    cout << " ";
                }
                cout << Nodes[i].name;
            }
            cout << endl;
        }
        return 0;
    }
    
    • 0
      @ 2025-9-4 21:59:46

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

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

      信息

      ID
      104
      时间
      1000ms
      内存
      512MiB
      难度
      2
      标签
      递交数
      43
      已通过
      10
      上传者