2023牛客寒假算法基础集训营1

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AC自动寄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值