2020牛客多校第二场 B.Boundary

在这里插入图片描述
题意:选择一个点使得这个点构成的圆 经过远点和其他点要求 求出经过点最多的圆的点的个数;

解法:pair 维护点个数和坐标,最后找最多的那个;
坑点:注意共线,注意最后可能是一个或者两个点的例外情况,注意公式正确

代码:

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-10;

struct Point{
	double x,y;
	Point(double x,double y){
		this->x=x;
		this->y=y;
	}
	Point(){
		x=y=0;
	}
};
Point p[5005];

Point waixin(Point a,Point b,Point c){
	double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
	double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
	double d = a1*b2 - a2*b1;
	return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 -a2*c1)/d);	
}
pair<double,double>mp[1005*2005];
int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	int n,k=0;
	scanf("%d",&n);
	double ta,tb;
	for(int i=0;i<n;i++){
		scanf("%lf%lf",&ta,&tb);
		p[i].x=ta;
		p[i].y=tb;
	}
	Point z(0,0);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(fabs(p[i].x*p[j].y-p[i].y*p[j].x)>eps){
				Point tmp=waixin(p[i],p[j],z);
				mp[k++]=make_pair(tmp.x,tmp.y);
			}
		}
	}
	if(k==0){
		printf("1\n");
		return 0;
	}
	int cnt=1,ans=1;
	sort(mp,mp+k);
	for(int i=1;i<k;i++){
		if(mp[i].first==mp[i-1].first&&mp[i].second==mp[i-1].second)
			cnt++,ans=max(ans,cnt);
		else cnt=1;
	}
	//cout<<ans<<endl;
	for(int i=1;i<=n;i++){
		if(i*(i-1)/2==ans){
			printf("%d\n",i);
			return 0;
		}
	}
	
	return 0;
}









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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值