codeforces 851 B. Arpa and an exam about geometry

来源:互联网 发布:mac上装ios模拟器 编辑:程序博客网 时间:2024/06/05 04:38

脑袋短路了,只要判断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
原创粉丝点击