UVA - 10041 Vito's Family 求中位数
来源:互联网 发布:json 数据解析 乱码 编辑:程序博客网 时间:2024/06/11 08:56
题目大意:有一个人要去拜访他的好友,给出他所有好友的位置,问如何才能使他到每个好友的家的距离之和最短
解题思路:求中位数
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;const int maxn = 500 + 5;float arr[maxn];int main() {int test;scanf("%d", &test);while(test--) {int num;float temp;float ans = 0;scanf("%d", &num);for(int i = 0; i < num; i++)scanf("%f", &arr[i]);sort(arr,arr+num);temp = (arr[(num-1)/2] + arr[num/2]) / 2;for(int i = 0; i < num; i++)ans = ans + abs(arr[i]- temp);printf("%.0f\n",ans);}return 0;}
0 0
- UVA - 10041 Vito's Family 求中位数
- UVA 10041 Vito's Family 求中位数 模拟
- UVA 10041 Vito's Family (中位数)
- UVa 10041 Vito's Family (中位数&快速选择)
- uva10041 - Vito's Family(求中位数)
- uva 10041 Vito's family
- UVa 10041 - Vito's Family
- UVa 10041 - Vito's Family
- uva 10041 - Vito's Family
- UVa 10041 - Vito's Family
- UVA 10041 - Vito's Family
- uva 10041 Vito's Family
- UVa 10041 - Vito's Family
- UVA-10041- Vito's family
- UVa 10041 - Vito's Family
- UVa 10041 - Vito's Family
- UVA - 10041 Vito's Family
- uva 10041 Vito's Family
- Oracle 控制文件(controlfile)
- 从容网掀起互联网金融新革命
- GestureDetector.OnGestureListener 详解
- 使用WinSCP软件在windows和Linux中进行文件传输
- lua实现的A星(a star)算法
- UVA - 10041 Vito's Family 求中位数
- Breakout detection in the wild
- AOJ 0121: Seven Puzzle (BFS DP STL 逆向推理)
- WPA和WPA2关系
- Linux cat 命令源码剖析
- 如何在Eclipse下将Maven打包的war部署到远程Tomcat
- NodeJS、NPM安装配置步骤(windows版本)
- Quartz 触发器(SimpleTrigger&CronTrigger )配置说明 & cronExpression表达式
- 第十一周项目4特殊三位数