// Vito’s Family (Vito 家族)
// PC/UVa IDs: 110401/10041, Popularity: A, Success rate: high Level: 1
// Verdict: Accepted
// Submission Date: 2011-05-21
// UVa Run Time: 0.104s
//
// 版权所有(C)2011,邱秋。metaphysis # yeah dot net
//
// 一组数据,如果要求一个数,该数与所有数据的差的绝对值和最小,则该数是这组数据的中位数。 #include <iostream>
#include <algorithm>using namespace std;#define MAXSIZE 500int main(int ac, char *av[])
{int cases, total;int address[MAXSIZE];cin >> cases;while (cases--){cin >> total;int counter = 0;while (counter < total)cin >> address[counter++];sort(address, address + total);// 找到中位数并求和,注意该题所求的中位数须为整数。int middle;if (total & 1)middle = address[total / 2];elsemiddle = (int) (((float) (address[total / 2 - 1] +address[total / 2]) * 5.0 + 5.0) / 10.0);long shortest = 0;for (int i = 0; i < total; i++){int distance = middle - address[i];shortest += (distance >= 0 ? distance : (-1) * distance);}cout << shortest << endl;}return 0;
}

UVa Problem 10041 Vito’s Family (Vito 家族)相关推荐

  1. UVa Problem 123 - Searching Quickly

    // UVa Problem 123 - Searching Quickly // Verdict: Accepted // Submission Date: 2012-01-04 // UVa Ru ...

  2. UVa Problem 109 - SCUD Busters

    // UVa Problem 109 - SCUD Busters // Verdict: Accepted // Submission Date: 2011-11-24 // UVa Run Tim ...

  3. UVa Problem 10310 Dog and Gopher (狗拿地鼠)

    // Dog and Gopher (狗拿地鼠) // PC/UVa IDs: 111301/10310, Popularity: A, Success rate: average Level: 1 ...

  4. UVa Problem 10001 Garden of Eden (伊甸园)

    // Garden of Eden (伊甸园) // PC/UVa IDs: 110806/10001, Popularity: B, Success rate: average Level: 2 / ...

  5. UVa Problem 10254 The Priest Mathematician (牧师数学家)

    // The Priest Mathematician (牧师数学家) // PC/UVa IDs: 110606/10254, Popularity: C, Success rate: high L ...

  6. UVa Problem 10067 Playing With Wheels (摆弄轮子)

    // Playing With Wheels (摆弄轮子) // PC/UVa IDs: 110902/10067, Popularity: C, Success rate: average Leve ...

  7. UVa Problem 10205 Stack ’em Up (完美洗牌术)

    // Stack 'em Up (完美洗牌术) // PC/UVa IDs: 110205/10205, Popularity: B, Success rate: average Level: 1 / ...

  8. 哈佛大学统计学教材_哈佛校友在职场上的统计数据

    哈佛大学统计学教材 By: Asher Noel and Alicia Wu 作者:Asher Noel和Alicia Wu On May 6, the Group for Undergraduate ...

  9. 整理:ACM相关好的网站 OJ Blog (不断更新)

    ACM-ICPC世界网站 http://acm.timus.ru http://acm.sgu.ru http://acm.hnu.cn http://acm.hdu.edu.cn http://ac ...

最新文章

  1. 深圳某女孩身家上千万,却称自己不配追求大厂程序员
  2. 华为p20可以用云闪付吗_华为hcIE有多难?零基础可以通过华为hcie认证吗?
  3. java if else嵌套,减少的 if else 嵌套 可以使用java 8的Consumer
  4. TensorFlow:实战Google深度学习框架(四)MNIST数据集识别问题
  5. JavaScript-jQuery操作Dom元素
  6. Maven——windows下安装配置及IDEA设置本地仓库的步骤总结
  7. 动态路由协议之OSPF
  8. select * from什么意思_SQL入门教程第15课:什么是内连接
  9. xshell 登录kail拒绝了密码 已解决
  10. 服务器开机信号,机柜服务器BMC开关机控制系统及方法
  11. bzoj 1046: [HAOI2007]上升序列【dp+二分】
  12. 比特币以太坊数字货币钱包安全助记词安全问题
  13. ios-后台运行UIApplication
  14. layui 之 laypage分页插件
  15. 五子棋(人人对战、人机对战均可)
  16. 微信小程序如何快速达到1000UV流量主开通要求
  17. 以太坊生态缺陷导致的一起亿级代币盗窃大案
  18. linux内核驱动使用hugepages,Linux系统下快速配置HugePages的完整步骤
  19. 如何执行IntelliJ IDEA 中的.sql文件
  20. 我打算去广东第一“鬼城”,买房安家

热门文章

  1. 怎样的年轻化法则,让这个品牌四年净利润复合增速达30%
  2. Fastadmin隐藏后台登录入口地址?
  3. 艾孜尔江在腾讯网上的影视作品
  4. MOSFET原理与应用
  5. 初识C语言 二(数据类型、变量和常量)
  6. 第8讲 - C语言关键字(8)
  7. (OK) dnf - Fedora23——删除多余不用的内核
  8. Win10系统U盘重装恢复出厂设置的方法
  9. 谈谈数据挖掘和机器学习
  10. STM32 Cube MX 之hal库软件模拟IIC 可直接移植使用