uva 10041 Vito's Family(检索)
来源:互联网 发布:已连接,但无法访问网络 编辑:程序博客网 时间:2024/05/17 21:41
题目连接:10041 - Vito's Family
题目大意:给出所有邻居的位置,要求找到一个位置,使得该位置到所有邻居家的总和最小。
解题思路:就是单纯的找中位数,记得先排序, 然后将数组遍历一遍求的最小值。
#include <stdio.h>#include <string.h>#include <algorithm>#include <stdlib.h>using namespace std;const int N = 30005;int peo[N];int main() { int cas, n, sum; scanf("%d", &cas); while (cas--) {sum = 0;memset(peo, 0, sizeof(peo));scanf("%d", &n);for (int i = 0; i < n; i++) scanf("%d", &peo[i]);sort(peo, peo + n);int cur = peo[(n + 1) / 2 - 1];for (int i = 0; i < n; i++) sum += abs(cur - peo[i]);printf("%d\n", sum); } return 0;}
- uva 10041 Vito's Family(检索)
- UVA - 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
- HDU 2098 分拆素数和
- Oracle优化器选择
- HDU 2096 小明A+B
- 用户级线程与内核级线程
- 找出第n大元素
- uva 10041 Vito's Family(检索)
- UVA 10815 Andy's First Dictionary 安迪的字典 stl应用 set+string做法
- easyUI 接收springMVC返回乱码问题
- 《我学习JAVA的方式》
- uva 507 Jill Rides Again(检索)
- socket编程
- volatile(在寄存器操作的时候要注意,具体的例子可以参考uboot里面代码)
- http的方法浅析
- AndroidRuntime(1185): android.os.NetworkOnMainThreadException 异常解决