1006: Triangle
Time Limit: 1 Sec Memory Limit: 32 MBSubmit: 30 Solved: 9
[ Submit][ Status][ Web Board]
Description
It is a simple task, for N points on the 2D plane, you are supposed to find whether there are three points which could form a isosceles triangle.
Input
There are several test cases. For each case, the first line is an integer N (3 <= N <= 500) indicating the number of points. N lines follow, each line contains two doubles(not exceed 1000.0), indicating the coordinates of the points.
Output
For each case, if there exists a solution which could form a isosceles triangle, output “YES”, else output “NO”.
Sample Input
Sample Output
#include<iostream>
#include<cmath>
using namespace std;
struct S
{
double x,y;
double dist;
}str[501];
int main(void)
{
int N;
while(cin>>N)
{
int i,j,k;
int flag=0;
for(i=0; i<N; i++)
{
cin>>str[i].x>>str[i].y;
}
for(i=0; i<N; i++)
{
for(j=0; j<N; j++)
{
str[j].dist=(str[i].x-str[j].x)*(str[i].x-str[j].x)+(str[i].y-str[j].y)*(str[i].y-str[j].y);
}
for(j=0; j<N; j++)
{
for(k=j+1; k<N; k++)
{
if(abs(str[j].dist-str[k].dist)<0.000001)
{
double x1=str[j].x-str[i].x;
double y1=str[j].y-str[i].y;
double x2=str[k].x-str[i].x;
double y2=str[k].y-str[i].y;
if(abs(x1*y2-x2*y1)>0.000001)
{
flag=1;
break;
}
}
}
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}