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> using namespace std; int fab(int x) { if(x>=0) return x; else return (-1)*x; } int comp(const void *e1,const void *e2) { return *(int *)e1 - *(int *)e2; } int main(){ int i; int *x,*y,*q; int n; while(cin>>n) { x=new int[n]; y=new int[n]; q=new int[n]; for(i=0;i<n;i++) cin>>x[i]>>y[i]; qsort(x,n,sizeof(int),comp); qsort(y,n,sizeof(int),comp); int middley=y[(n+1)/2-1]; int middlex=x[(n+1)/2-1]; int k=(n+1)/2-1; for(i=0;i<n;i++) { q[i]=fab(x[i]-(middlex-k+i)); } int sumy=0,sumx=0; for(i=0;i<n;i++) { sumy+=fab(middley-y[i]); sumx+=q[i]; } cout<<sumy+sumx<<endl; delete[] x;delete[] y; delete[]q; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator