Triangle

本文介绍了一种通过计算平面上给定点集中的点之间的距离来判断是否存在等腰三角形的方法。利用枚举和平面几何原理,该算法有效地解决了这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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\n");
                            flag=true;
                            goto result;
                        }
                    }
                }
            }
        }
        result: ;
        if(!flag)
            printf("NO\n");
    }
    return 0;
}

FROM:暑假第一场

/*****************************************************************************/ /* */ /* 888888888 ,o, / 888 */ /* 888 88o88o " o8888o 88o8888o o88888o 888 o88888o */ /* 888 888 888 88b 888 888 888 888 888 d888 88b */ /* 888 888 888 o88^o888 888 888 "88888" 888 8888oo888 */ /* 888 888 888 C888 888 888 888 / 888 q888 */ /* 888 888 888 "88o^888 888 888 Cb 888 "88oooo" */ /* "8oo8D */ /* */ /* A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator. */ /* (triangle.c) */ /* */ /* Version 1.6 */ /* July 28, 2005 */ /* */ /* Copyright 1993, 1995, 1997, 1998, 2002, 2005 */ /* Jonathan Richard Shewchuk */ /* 2360 Woolsey #H */ /* Berkeley, California 94705-1927 */ /* [email protected] */ /* */ /* This program may be freely redistributed under the condition that the */ /* copyright notices (including this entire header and the copyright */ /* notice printed when the `-h' switch is selected) are not removed, and */ /* no compensation is received. Private, research, and institutional */ /* use is free. You may distribute modified versions of this code UNDER */ /* THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT IN THE */ /* SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH SOURCE */ /* AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR */ /* NOTICE IS GIVEN OF THE MODIFICATIONS. Distribution of this code as */ /* part of a commercial system is permissible ONLY BY DIRECT ARRANGEMENT */ /* WITH THE AUTHOR. (If you are not directly supplying this code to a */ /* customer, and you are instead telling them how they can obtain it for */ /* free, then you are not required to make any arrangement with me.)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值