UVa Problem Solution: 10041 - Vito's Family
来源:互联网 发布:淘宝客工具 编辑:程序博客网 时间:2024/05/18 01:04
Vito should live on the street which is the median of his relatives.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 10041 C++ "Vito's Family" */
- #include <algorithm>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- #include <string>
- #include <vector>
- using namespace std;
- int min_dist_sum(int *first, int *last)
- {
- int *median = first + (last - first) / 2;
- nth_element(first, median, last);
- int sum = 0;
- for (; first < median; ++first)
- sum += *median - *first;
- for (; first < last; ++first)
- sum += *first - *median;
- return sum;
- }
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- filebuf in, out;
- cin.rdbuf(in.open((string(argv[0]) + ".in").c_str(), ios_base::in));
- cout.rdbuf(out.open((string(argv[0]) + ".out").c_str(), ios_base::out));
- #endif
- int ncases;
- cin >> ncases;
- while (ncases-- > 0) {
- int r;
- cin >> r;
- int s[500];
- for (int i = 0; i < r; ++i)
- cin >> s[i];
- cout << min_dist_sum(s, s + r) << '/n';
- }
- return 0;
- }
- UVa Problem Solution: 10041 - Vito's Family
- UVa Problem 10041 Vito’s Family (Vito 家族)
- 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
- Uva 10041 Vito's Family
- uva 10041 Vito's Family
- UVa, 10041 Vito's Family UVa, 10041
- 实例入门Ajax(改进)
- 李开复经历过三种模式的裁员:
- c与java中计算程序执行时间的方法
- sql 2005 锁的分析学习
- BI是什么
- UVa Problem Solution: 10041 - Vito's Family
- winhand.cpp Line XX错误
- 商业智能 2.0(BI2.0 from Wikipedia)
- 追忆Tapstry4.0------学习笔记(三)
- typedef的四个用途和两个陷阱
- GOF设计模式
- 移植Android开发过程
- kernel源码的说明
- .NET鼠标右键菜单JS[原]