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

帮忙看看啊,自己查不出来了~~~~~~~~~~

Posted by nopeak at 2005-01-30 17:00:37 on Problem 1788
#include<stdio.h>
#define ABS(x) (x)>0?(x):(-(x))
typedef struct
{
	int x;
	int y;
	int num;
}post;

void main()
{
	long i,j,n,l,k;
	post p[10000],temp;
	while(1)
	{
	    scanf("%ld",&n);
		if(n==0)break;
	    for(l=0,k=0,i=0;i<n;i++)
		{
		    scanf("%d%d",&p[i].x,&p[i].y);
		    p[i].num=0;
		    for(j=k;j<i;j++)
			{
			    if(p[i].x==p[j].x){l+=ABS(p[i].y-p[j].y);p[i].num++;p[j].num++;}
			    else if(p[i].y==p[j].y){l+=ABS(p[i].x-p[j].x);p[i].num++;p[j].num++;}
			    if(p[j].num==2){temp=p[j];p[j]=p[k];p[k]=temp;k++;}
			    if(p[i].num==2){temp=p[i];p[i]=p[k];p[k]=temp;k++;break;}
			}
		}
		printf("\nThe length of the fence will be %d units.\n",l);
	}
}

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