武大校赛资格赛 求方差
发布日期:2021-10-08 15:48:48 浏览次数:3 分类:技术文章

本文共 1915 字,大约阅读时间需要 6 分钟。

Problem 1570 - G - April disease
Time Limit: 1000MS    
Memory Limit: 65536KB    
Total Submit: 210   
Accepted: 105   
Special Judge: No
Description
Holding a contest is an interesting mission, and apparently arranging the problems is not exceptional, either.
You may consider that there are N problems prepared, and it's required to choose M problems to form the problem set of the upcoming contest.
What's more, the evaluating function of all the problems choosed is as follows:
Where Xi represents the hardness of the i_th problem and X represents the average of the M problems.
However, the contest principal Alice has lost himself in April disease, and just wants to hold the worst contest ever.(Sounds horrible...)
Now he wonders, what's the minimum value of s^2 can be.
Input
The first line of each test case contains two numbers N and M. ( 1 <= M <= N <= 30 )
The following line will contain N numbers Xi. ( 1 <= Xi <= 10^9 )
Output
For each test case, output your answer in one line.
(Please keep three decimal places.)
Sample Input
4 3
6 10 1 2
5 2
1 8 3 4 9
Sample Output
4.667
0.250

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long longusing namespace std;const LL mod = 1e9 + 7;const double PI = acos(-1.0);const int M = 105;double a[M];double calc(int l, int r){ double sum = 0; for(int i = l; i <= r; ++i) sum += a[i]; int len = r - l + 1; double x = (double)(sum / len); double ans = 0; for(int i = l; i <= r; ++i){ ans += (a[i] - x) * (a[i] - x); } ans /= len; return ans;}int main(){ int m, n; while( cin >> n >> m ){ for(int i = 0; i < n; ++i) cin >> a[i]; sort(a,a + n); double ans = 999999999; for(int i = 0; i <= n - m; ++i){ ans = min(ans,calc(i,i + m - 1)); } printf("%.3f\n",ans); } return 0;}

 

转载地址:https://blog.csdn.net/ONE_PIECE_HMH/article/details/45131395 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UVA11538俩皇后可以相互攻击的方法,使用平方和公式将时间复杂度降到o(1)
下一篇:武大校赛资格赛 最小矩阵覆盖

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月19日 12时27分06秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

python启动远端 exe_python打包exe开机自动启动的实例(windows) 2019-04-21
java当前路径_java获取当前路径的几种方法 2019-04-21
java web传递参数_Javaweb的八种传值方式 2019-04-21
java gui支持的包有哪两个_Java GUI 2019-04-21
java list详解_java集合List解析 2019-04-21
java坐标代码_java实现计算地理坐标之间的距离 2019-04-21
kettle调用java程序_Kettle ETL调用 java代码来进行数据库的增删改查 2019-04-21
mysql 取两个时间差 php_在php和MySql中计算时间差的方法详解 2019-04-21
mysql 重启数据库实例_mysql 单机多实例重启数据库服务 2019-04-21
collator java_Java Collator getInstance(Locale)用法及代码示例 2019-04-21
dtc mysql_DTCC归来-高可用可扩展数据库架构探讨 2019-04-21
java怎样将日期本土化_Java中的日期操作 2019-04-21
java生产者消费者模型到精通_java生产者消费者模型 2019-04-21
java 执行 awk_3.1 biostar lesson3 linux学习日记;java版本;awk 2019-04-21
python函数代码块以什么开头_Python初体验-开篇 代码全析 2019-04-21
java闹钟程序设计_JAVA课程设计_闹钟的设计与实现项目-报告_附源代码.doc 2019-04-21
java中的无效的列类型_java.sql.SQLException: 无效的列类型: 1111 2019-04-21
php rewrite url_PHP_URL Rewrite的设置方法,URL Rewrite需要服务器的支持! - phpStudy 2019-04-21
php读取大文件某行内容,PHP读取和修改大文件的某行内容_PHP教程 2019-04-21
打印php错误日志,php怎样打印错误日志 2019-04-21