HDU1077---Catching Fish HDU(85)

本文介绍了一个算法问题,旨在解决在任意圆心的以1.0000001半径内寻找最多数量的“鱼”。算法通过计算圆心与各点的距离并筛选符合条件的点来实现。重点在于理解距离计算、圆心确定以及如何高效地找到最大数量的点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

const static double  eps = 1e-6;

struct Point
{
	double x,y;
};
double distancess(Point a,Point b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
Point look_center(Point a,Point b)
{
	Point aa,bb,mid;
	aa.x = b.x-a.x;
	aa.y = b.y-a.y;
	mid.x = (a.x+b.x)/2.0;
	mid.y = (a.y+b.y)/2.0;
	double dist = distancess(a,mid);
	double c = sqrt(1.0-dist);
	if(fabs(aa.y)<eps)
	{
		bb.x = mid.x;
		bb.y = mid.y+c;
	}

	else
	{
		double ang = atan(-aa.x/aa.y);
		bb.x = mid.x + c*cos(ang);
		bb.y = mid.y + c*sin(ang);
	}
	return bb;
}
int main()
{
	int test;
	Point p[305],a,b,c;
	int n;
	scanf("%d",&test);
	while(test--)
	{
		scanf("%d",&n);
		for(int i=0; i<n;i++)
			scanf("%lf%lf",&p[i].x,&p[i].y);

		int ans = 1;
		int temp = 0;
		for(int i=0; i<n; i++)
			for(int j=i+1;j<n;j++)
			{

				if(distancess(p[i],p[j])>4) continue;
				a = look_center(p[i],p[j]);
				temp = 0;
				for(int k=0;k<n;k++)
				{
					if(distancess(a,p[k])<=1.000001) temp++;
				}
				if(ans<temp) ans = temp;
			}
			printf("%d\n",ans);
	}
	return 0;

}

题目说的是求在任意圆心的以1.0000001半径以内的最大鱼的数目。

这个我有思路,但是一些公式不会求。

所以就直接借鉴了大神的公式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值