2020牛客暑期多校训练营(第二场)B.Boundary(计算几何)

题目

n(n<=2e3)个点,整点(x,y)(|x|,|y|<=1e4),保证两点不同,没有点位于原点

选最多的点,使之这些点在一个共同的圆上,且这个圆也过(0,0),输出最大数量

思路来源

官方题解

题解

大暴力可以枚举圆心,对任意两个点三点共圆确定的圆心统计答案,

设同一圆心的点对数量为p,则x*(x-1)/2=p的x即为答案

但是,这里可以考虑枚举P点,

利用同弧对应的圆心角相等,去求∠PAO相同的角共有多少个

避免出现图中A1、A2的情况,可以考虑强行约束OP在OA的逆时针

这里防double爆精度问题,采用了存cosC的符号*cosC的平方方法,用于比较cosC

代码

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef __int128_t LLL;
#define N 2000 + 5

int n, ans = 1, X[N], Y[N];

struct Frac
{
	LL fz, fm;
	Frac() : Frac(0, 1){}
	Frac(LL fz, LL fm) : fz(fz), fm(fm) {}
	bool operator < (const Frac &rhs)
	{
		return (LLL) fz * rhs.fm < (LLL) fm * rhs.fz;
	}
	bool operator == (const Frac &rhs)
	{
		return (LLL) fz * rhs.fm == (LLL) fm * rhs.fz;
	}
}A[N];

int Cross(int lhs, int rhs)
{
	return X[lhs] * Y[rhs] - X[rhs] * Y[lhs];
}

int Dot(int lhs, int rhs)
{
	return X[lhs] * X[rhs] + Y[lhs] * Y[rhs];
}

int Dis2(int lhs, int rhs)
{
	int dx = X[lhs] - X[rhs], dy = Y[lhs] - Y[rhs];
	return dx * dx + dy * dy;
}

int Sgn(int x)
{
	if (x > 0) return 1;
	if (x < 0) return -1;
	return 0;
}

Frac GetCosAngle2(int i, int j)
{
	int a2 = Dis2(0, i), b2 = Dis2(i, j), c2 = Dis2(0, j);
	int sgn = Sgn(b2 + c2 - a2);
	return Frac(1LL * sgn * (b2 + c2 - a2) * (b2 + c2 - a2), 4LL * b2 * c2);//cosC*cosC 加上cosC的符号用于区分 
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf("%d%d", X + i, Y + i);
	for (int i = 1; i <= n; i ++)
	{
		int cnt = 0;
		for (int j = 1; j <= n; j ++)
			if (Cross(i, j) > 0)
				A[++ cnt] = GetCosAngle2(i, j);
		sort(A + 1, A + cnt + 1);
		for (int l = 1, r; l <= cnt; l = r)
		{
			for (r = l; A[l] == A[r] && r <= cnt; r ++) ;
			ans = max(ans, r - l + 1);
		}
    }
	printf("%d\n", ans);
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Code92007

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

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

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

打赏作者

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

抵扣说明:

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

余额充值