zoukankan      html  css  js  c++  java
  • PAT 天梯赛 L2-015. 互评成绩 【排序】

    题目链接

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

    思路
    在求和的过程中 标记一下 最大值和最小值,在最后求平均的时候 用总和减去最大值和最小值 去除 (总数 - 2) 然后最后排序的时候 先按升序来排 然后 最后 POP 掉 多余的 再按升序来排

    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 = 1e6 + 5;
    const int MOD  = 1e9 + 7;
    
    bool comp(double x, double y)
    {
        return x > y;
    }
    
    int main()
    {
        int n, k, m;
        scanf("%d%d%d", &n, &k, &m);
        vector <double> v;
        v.clear();
        for (int i = 0; i < n; i++)
        {
            int Min = MAXN, Max = MINN;
            double sum = 0;
            int num;
            for (int j = 0; j < k; j++)
            {
                scanf("%d", &num);
                Min = min(Min, num);
                Max = max(Max, num);
                sum += num;
            }
            sum = (sum - Min - Max) * 1.0 / (k - 2);
            v.push_back(sum);
        }
        sort(v.begin(), v.end(), comp);
        while (v.size() > m)
            v.pop_back();
        sort(v.begin(), v.end());
        vector <double>::iterator it;
        int i;
        for (it = v.begin(), i = 0; it != v.end() && i < m; i++, it++)
        {
            if (i)
                printf(" ");
            cout << setprecision(3) << std::fixed <<  (*it);
        }
    }
  • 相关阅读:
    [POJ1743]Musical Theme
    ubuntu qq
    Separate code and data contexts: an architectural approach to virtual text sharing
    Python3发送post请求,自动记住cookie
    python 异步协程
    豆瓣爬虫
    pandas 使用
    房天下爬虫
    计算英文文章词频的两种方法
    LOW版统计词频
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433265.html
Copyright © 2011-2022 走看看