E 鸡算几何
思路:
- 计算几何的叉积概念
- 叉积:如果在AB,BC两条线段中,若 BC在BA线段的逆时针180度以内,则cross(BA, BC)为正数,反之,超过180则为负数,若BA, BC共线则 cross(BA, BC)为 0
- 注意精度不要过小(1e-9),1e-5合理就可以,过大过小都不太好。
代码如下:
// Time: 2023-01-17 20:28:07
// Problem: 鸡算几何
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/50778/E
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
#include <algorithm>
#include <iostream>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define fast ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define mkpr make_pair
#define endl '\n'
#define x first
#define y second
#define y1 Y1
// #define int long long
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int N = 2e5 + 10, M = N * 2;
LL gcd(LL a,LL b){return b ? gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
int T = 1, cases = 1;
int n, m, times;
PDD a, b, c, d, e, f;
double dist(PDD a, PDD b)
{
double dx = a.x - b.x;
double dy = a.y - b.y;
double res = sqrt(dx * dx + dy * dy);
return res;
}
double cross(PDD a, PDD b, PDD c)
{
double x1 = a.x - b.x;
double y1 = a.y - b.y;
double x2 = c.x - b.x;
double y2 = c.y - b.y;
double res = x1 * y2 - x2 * y1;
return res;
}
void solve()
{
cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
cin >> d.x >> d.y >> e.x >> e.y >> f.x >> f.y;
if (fabs(dist(a, b) - dist(c, b)) < eps)
{
cout << "NO" << endl;
return;
}
if (!(fabs(dist(a, b) - dist(d, e)) < eps)) swap(a, c);
double res1 = cross(a, b, c), res2 = cross(d, e, f);
if (res1 > 0 && res2 > 0 || res1 < 0 && res2 < 0) cout << "NO" << endl;
else cout << "YES" << endl;
return;
}
signed main()
{
//fast;
cin >> T;
//scanf("%d", &T);
while(T -- )
solve();
return 0;
}