您的位置:首页 > 其它

codeforces 851 B. Arpa and an exam about geometry

2017-09-05 22:45 375 查看
脑袋短路了,只要判断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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: