Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
C#include <stdio.h> #include <stdlib.h> int get_abs(int a) { return a>0?a:-a; } int comp(const void *a,const void *b) { return (*(int *)a-*(int *)b); } int main() { int x[10000],y[10000]; int n; int i; long int sum=0; int std; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",x+i,y+i); } qsort(x,n,sizeof(int),comp); for(i=0;i<n;i++) x[i]-=i; qsort(x,n,sizeof(int),comp); std=x[n/2]; for(i=0;i<n;i++) sum+=get_abs(x[i]-std); qsort(y,n,sizeof(int),comp); std=y[n/2]; for(i=0;i<n;i++) sum+=get_abs(y[i]-std); printf("%ld\n",sum); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator