zoukankan      html  css  js  c++  java
  • Triangle

    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

    3
    0 0
    1 1
    -1 1
    3
    0 0
    1 1
    5 10

    Sample Output

    YES
    NO
    思路:题目大致意思是给你已知数的点,求出这些点之间是否能组成等腰三角形。
    可以枚举所有点,求出一点到其他所有点的距离,如果有两个相等的距离并且没在同一直线上,则组成等腰三角形。
    代码:
    #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
    ");
                                flag=true;
                                goto result;
                            }
                        }
                    }
                }
            }
            result: ;
            if(!flag)
                printf("NO
    ");
        }
        return 0;
    }
    

    FROM:暑假第一场

  • 相关阅读:
    git常用命令及多人协同开发及遇到的问题
    LightOJ
    LightOJ
    LightOJ
    LightOJ
    LightOJ
    LightOJ
    LightOJ
    LightOJ
    Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3188384.html
Copyright © 2011-2022 走看看