| ||||||||||
| 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 | |||||||||
帮忙看看啊,自己查不出来了~~~~~~~~~~
#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator