PAT 天梯赛 L2-015. 互评成绩 【排序】
2024-09-12 08:36:29
题目链接
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);
}
}
最新文章
- set 集合容器实现元素的插入与中序排序
- Java_解密ThreadLocal
- JaxWsDynamicClientFactory弃用了,改成org.codehaus.xfire.client;
- SCCM2007
- 使用ffmpeg实现转码样例(代码实现)
- Phalcon 的 bootstrap.php 自动加载完成;非常人性化的设计
- 14.3 InnoDB Multi-Versioning InnoDB 多版本
- IOS 排序算法
- 设计模式10---设计模式之原型模式(Prototype)
- HDU 5810 Balls and Boxes
- PHP Markdown 解析器Parsedown
- [Angular Tutorial] 11 -Custom Filters
- springmvc03-异常处理-静态文件
- Vue生命周期中mounted和created的区别
- 跟踪OceanLotus的新下载程序KerrDown
- 初识HDFS原理及框架
- “建议127:Lock与synchronized是不一样的问题”实际验证
- 257. Binary Tree Paths返回所有深度优先的遍历
- 读取二元组列表,打印目录的层级结构-----C++算法实现
- 案例25-servlet的抽取