L2-009 抢红包 (25 分)

摘要
Title: L2-009 抢红包 (25 分)
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

L2-009 抢红包 (25 分)

  • 题意

    没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。

  • 思路

    模拟即可

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    /*
    * @Author: NEFU AB-IN
    * @Date: 2022-04-20 20:47:30
    * @FilePath: \ACM\GPLT\L2-009.CPP
    * @LastEditTime: 2022-04-20 20:56:41
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    #define MP make_pair
    #define SZ(X) ((int)(X).size())
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(0); \
    cout.tie(0);
    #define DEBUG(X) cout << #X << ": " << X << endl;
    typedef pair<int, int> PII;
    const int INF = 0x3f3f3f3f;

    const int N = 1e4 + 10;
    int n;
    int cnt[N];
    double sum[N];

    struct sa
    {
    int id, cnt;
    double sum;
    };

    signed main()
    {
    IOS;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
    int k;
    double sum1 = 0.0;
    cin >> k;
    for (int j = 1; j <= k; ++j)
    {
    int v;
    double p;
    cin >> v >> p;
    cnt[v] += 1;
    sum[v] += p;
    sum1 += p;
    }
    sum[i] -= sum1;
    }
    vector<sa> v;
    for (int i = 1; i <= n; ++i)
    {
    v.push_back({i, cnt[i], sum[i]});
    }

    sort(v.begin(), v.end(), [&](sa a, sa b) {
    if (a.sum != b.sum)
    return a.sum > b.sum;
    else if (a.cnt != b.cnt)
    return a.cnt > b.cnt;
    return a.id < b.id;
    });

    for (auto [id, cnt_, sum_] : v)
    {
    printf("%lld %.2lf\n", id, sum_ / 100.0);
    }
    return 0;
    }
使用搜索:谷歌必应百度