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.
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.
For each case, if there exists a solution which could form a isosceles triangle, output “YES”, else output “NO”.
#include <iostream> #include <math.h> #include <stdio.h> #include<algorithm> using namespace std; struct point { double x, y; double dis; }p[520]; int main() { freopen("tri.in", "r", stdin); freopen("tri.out","w", stdout); int n; while(~scanf("%d", &n)){ int flag =0; for(int i=0; i<n; i++) scanf("%lf %lf", &p[i].x, &p[i].y); for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ p[j].dis=(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y); } for(int j=0; j<n; j++){ for(int k=j+1; k<n; k++){ if(fabs(p[j].dis-p[k].dis)<0.000001){ double x1=p[j].x-p[i].x; double y1=p[j].y-p[i].y; double x2=p[k].x-p[i].x; double y2=p[k].y-p[i].y; if(fabs(x1*y2-x2*y1)>0.000001){ flag=1; break; } } } } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0; }