hdu 2083 简易版之最短距离
2013-02-14 00:16
330 查看
肯跌的中位数,当有3个从小到大的数,a,b,c;b到a, b,c的和为c-a不是b点都大于或等于c-a推广到多项就是中位数
#include<iostream> #include<cmath> #include<algorithm> #define Max 502 using namespace std; int ch[Max]; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int t; scanf("%d", &t); while(t--) { int n, i, s = 0; scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d", &ch[i]); qsort(ch, n, sizeof(int), cmp); for(i = 0; i < n; i++) s += abs(ch[n/2] - ch[i]); printf("%d\n", s); } return 0; }
相关文章推荐
- HDU 2083 简易版之最短距离
- Hdu 2083 简易版之最短距离
- HDU 2083 简易版之最短距离
- hdu 2083 简易版之最短距离
- HDOJ(HDU) 2083 简易版之最短距离(中位数)
- HDOJ(HDU) 2083 简易版之最短距离(中位数)
- HDU 2083 简易版之最短距离
- hdu - 2083 - 简易版之最短距离
- hdu 2083 简易版之最短距离
- HDU:2083 简易版之最短距离(水)
- hdu 2083 简易版之最短距离
- hdu 2083 简易版之最短距离
- HDU 2083 简易版之最短距离
- hdu 2083 简易版之最短距离
- HDU 2083 简易版之最短距离
- HDU ACM 11 2083 简易版之最短距离
- 简易版之最短距离 HDU - 2083
- HDU 2083 简易版之最短距离
- HDU 2083 简易版之最短距离
- HDU 2083 简易版之最短距离(快排)