Problem Description:
There are many light house in the sea. The range of the sea is [1, 10^7] × [1, 10^7]
.
Each light house can light up the south-west and north-east area. The power of the light is enought to cover any distance.
If the light house A and B are in there lighting up area, says they can illuminate each other.
input has n+1 lines: the first line is the number of light house. the second line to the nth line are the horizontal and vertical coordinate of the light house.
output has one line: the pair of light house which can illuminate each other.
for example:
intput:
3
2 2
4 3
5 1
output:
1
note:
The coordinate of the light house is int. The horizontal and vertical coordinate of all the light houses are different.
1 ≤ x, y ≤ 10^7
the efficiency of my code is very low. Please help me revise my code. Thank you very much!
Here is my code.
#include<stdlib.h>
int main()
{
int n,i,j,s;
int *x,*y;
scanf("%d",&n);
x=(int *)malloc(n*sizeof(int));
y=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d %d",&x[i],&y[i]);
}
s=0;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if((x[i]>x[j]&&y[i]>y[j])||(x[i]<x[j]&&y[i]<y[j]))
s++;
}
printf("%d\n",s);
free(x);
free(y);
return 0;
}