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 |
所有数据都通过还是WA#include<iostream> #include<cstdlib> #include<cstdio> using namespace std; #define N 10000 int n; struct position { int px; int py; }; int cmp(const void *a,const void *b) { return *((int *)a)-*((int *)b); } int median(int s[N],int size) { if(size%2==1) { return s[size/2]; } else { return (s[size/2]+s[size/2-1])/2; } } int _abs(int number) { if(number<0) return number*-1; else return number; } int main() { struct position soldier[N]; int i; int midx,midy; int killer[N],distx[N]; int result=0; cin>>n; for(i=0;i<n;i++) { cin>>soldier[i].px>>soldier[i].py; } for(i=0;i<n;i++) { killer[i]=soldier[i].py; } qsort(killer,n,sizeof(int),cmp); midy=median(killer,n); for(i=0;i<n;i++) { result+=_abs(midy-killer[i]); } for(i=0;i<n;i++) { killer[i]=soldier[i].px; } qsort(killer,n,sizeof(int),cmp); midx=median(killer,n); for(i=0;i<n;i++) { distx[i]=midx-(n/2-i); } for(i=0;i<n;i++) { result+=_abs(distx[i]-killer[i]); } cout<<result<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator