codeforces 851 B. Arpa and an exam about geometry

脑袋短路了,只要判断AB和BC距离是否同样就好了。写的时候有点短路,判断多了。。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-8;
struct Point
{
    Point(){}
    Point(double _a, double _b):x(_a),y(_b){}
    double x,y;
};
Point ps[3];

int sgn(double x)
{
    if(fabs(x) <= eps) return 0;
    if(x > 0) return 1;
    return -1;
}

double dist(Point a, Point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

bool check()
{
    Point cen((ps[0].x+ps[2].x)/2.0,(ps[0].y+ps[2].y)/2.0);
    Point ac(ps[2].x-ps[0].x,ps[2].y-ps[0].y);
    Point cenb(ps[1].x-cen.x,ps[1].y-cen.y);
    double t = ac.x*cenb.x+ac.y*cenb.y;

    Point ab(ps[1].x-ps[0].x,ps[1].y-ps[0].y);
    Point bc(ps[2].x-ps[1].x,ps[2].y-ps[1].y);
    double cj = ab.x*bc.y-ab.y*bc.x;
    return sgn(t)==0 && sgn(cj) != 0;
}

int main()
{
    ios::sync_with_stdio(false);
    for(int i = 0; i < 3; ++i)
        cin >> ps[i].x >> ps[i].y;
    double dis1,dis2,dis3;
    dis1 = dist(ps[0],ps[1]);
    dis2 = dist(ps[0],ps[2]);
    dis3 = dist(ps[1],ps[2]);
    if((sgn(dis1-dis2) == 0 || sgn(dis1-dis3) == 0 || sgn(dis2-dis3) == 0)
       && check())
        cout << "Yes" <<endl;
    else
        cout << "No" << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值