Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手指点一下为什么我的程序WA呢??帮帮忙了啦

Posted by 382784268 at 2009-02-25 12:39:14 on Problem 1723
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator