1006: Triangle
Time Limit: 1 Sec Memory Limit: 32 MB Submit: 29 Solved: 8
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<cstring> #include<stdio.h> #include<cmath> #include<algorithm> using namespace std; #define MAX 505 #define ERR 0.000001 struct Point { double x,y; }point[MAX]; double dis[MAX]; int main() { int n,i,j,k; while(scanf("%d",&n)!=EOF) { bool flag=false; for(i=1;i<=n;i++) scanf("%lf%lf",&point[i].x,&point[i].y); for(i=1;i<=n;i++) { memset(dis,0,sizeof(dis)); for(j=1;j<=n;j++) { dis[j]=sqrt(((point[i].x-point[j].x)*(point[i].x-point[j].x))+((point[i].y-point[j].y)*(point[i].y-point[j].y))); } for(j=1;j<=n;j++) { for(k=j+1;k<=n;k++) { if(fabs(dis[j]-dis[k])<ERR) { if((fabs((point[j].x-point[i].x)*(point[k].y-point[j].y)-(point[j].y-point[i].y)*(point[k].x-point[j].x))>ERR)) { printf("YES\n"); flag=true; goto result; } } } } } result: ; if(!flag) printf("NO\n"); } return 0; }
FROM:暑假第一场