zoukankan      html  css  js  c++  java
  • PAT 天梯赛 L2-009. 抢红包 【排序】

    题目链接

    https://www.patest.cn/contests/gplt/L2-009

    思路

    用结构体存储,然后结构体排序 注意一下 个人编号是从 1 开始
    计数的
    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    
    using namespace std;
    typedef long long LL;
    
    const double PI  = 3.14159265358979323846264338327;
    const double E   = 2.718281828459;
    const double eps = 1e-6;
    
    const int MAXN = 0x3f3f3f3f;
    const int MINN = 0xc0c0c0c0;
    const int maxn = 1e4 + 5;
    const int MOD  = 1e9 + 7;
    
    struct Node
    {
        int tot, id;
        double sum;
    }q[maxn];
    
    bool comp(Node x, Node y)
    {
        if (x.sum == y.sum)
        {
            if (x.tot == y.tot)
                return x.id < y.id;
            return x.tot > y.tot;
        }
        return x.sum > y.sum;
    }
    
    int main()
    {
        memset(q, 0, sizeof(q));
        int n;
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            q[i].id = i;
        for (int i = 0; i < n; i++)
        {
            int k;
            scanf("%d", &k);
            int id, num;
            for (int j = 0; j < k; j++)
            {
                scanf("%d%d", &id, &num);
                q[id - 1].sum += num;
                q[id - 1].tot ++;
                q[i].sum -= num;
            }
        }
        sort (q, q + n, comp);
        for (int i = 0; i < n; i++)
            printf("%d %.2lf
    ", q[i].id + 1, q[i].sum / 100);
    }
  • 相关阅读:
    scala泛函编程是怎样被选中的
    新一代编程:scala泛函编程技术-唠叨
    maven依赖本地非repository中的jar包【转】
    关于maven的profile
    intellij idea使用技巧
    springmvc的过滤器和拦截器
    spring bean的生命周期
    关于spring的bean
    关于递归
    tcp
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433263.html
Copyright © 2011-2022 走看看