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 zsc08_wangqiang at 2010-02-18 01:02:47 on Problem 1788
#include<iostream>
using namespace std;
#define M 100001

struct IN
{
	int x,y;
}node[M];

int cmpx(const void *a,const void *b)
{
	if((*(IN *)a).x == (*(IN *)b).x)
		return (*(IN *)a).y - (*(IN *)b).y;
	else
		return (*(IN *)a).x - (*(IN *)b).x;
}
int cmpy(const void *a,const void *b)
{
	if((*(IN *)a).y == (*(IN *)b).y)
		return (*(IN *)a).x - (*(IN *)b).x;
	else
		return (*(IN *)a).y - (*(IN *)b).y;
}
int main()
{
	int i,j;
	int p,sum;
	while(scanf("%d",&p) && p!=0)
	{
		for(i=0; i<p; i++)
		{
			scanf("%d%d",&node[i].x,&node[i].y);
		}
		qsort(node,p,sizeof(node[0]),cmpx);
		sum = 0;
		for(i=0; i<p; i++)
		{
			if(i%2)
				sum += node[i].y;
			else
				sum -= node[i].y;
		}
		qsort(node,p,sizeof(node[0]),cmpy);
		for(i=0; i<p; i++)
		{
			if(i%2)
				sum += node[i].x;
			else
				sum -= node[i].x;
		}
		printf("Then thength of the fence will be %d units.\n",sum);
	}
	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