Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  distance
Language: C/C++
Code:
#include<stdio.h>
int dist(int,int,int,int);
main()
{
int n,i,j,k,l,min,t1,t2,p1,p2;
int arr[100][2];
scanf("%d",&n);
for(i=0;i<n;i++)
{for(j=0;j<2;j++)
scanf("%d",&arr[i][[j]);
}
t1=arr[0][0];
for(i=0;i<n;i++)
{if(arr[i][0]>t1)
t1=arr[i][0];
}
t2=arr[1][0];
for(i=0;i<n;i++)
{if(arr[i][1]>t2)
t2=arr[i][1];
}
min=dist(t1,t2,arr[0][0],arr[0][1]);
for(i=0;i<t1;i++)
{for(j=0;j<t2;j++)
{k=dist(i,j,arr[0][0],arr[0][1])+dist(i,j,arr[1][0],arr[1][1])+dist(i,j,arr[2][0],arr[2][1])+dist(i,j,arr[3][0],arr[3][1]);
if(k<min)
p1=i;p2=j;
}
}
printf("%d %d",p1,p2);
}
int dist(int t1,int t2,int x1,int x2)
{
int sum1,sum2,l;
sum1=x1-t1;
sum2=x2-t2;
if(sum1<0)
sum1=-sum1;
if(sum2<0)
sum2=-sum2;
l=sum1+sum2;
return l;
}     
Comments: