题目链接

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);
}
}

最新文章

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

热门文章

  1. codeblocks如何watch指针
  2. string 的函数
  3. driver基础
  4. go的map获取对应的key-value
  5. php对gzip文件或者字符串解压实例参考
  6. Servlet 国际化
  7. 什么是 AJAX?
  8. .net全局定时定期执行某些操作在Global.asax中具体实现
  9. 转:python 多线程就这么简单
  10. NetBeans执行项目报错