csp模测4th_T2 - ZJM要抵御宇宙射线

T2 - ZJM要抵御宇宙射线


题目描述

在这里插入图片描述
在这里插入图片描述

题目思路

这个题目其实上降低了一点难度,因为它规定保护罩的中心是位于一个宇宙射线的发射点上的。这样我们就只需要遍历所有的点,然后找到每个点以它为圆心包含所有点的最小圆,即找出距离中心点最远的点。然后再在所有的圆里面找到面积最小的圆即可。如果没有规定保护罩的中心在宇宙射线的发射点上的话就会稍微麻烦一点。

代码实现

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1010;
const double inf = 1e12;

int n;
struct circle{
	double x,y;
	double area;
	
	circle(){
		x = y = 0;
		area = inf;
	} 
	bool operator < (const circle& t)const{
		if(area != t.area) return area < t.area;
		else if(x != t.x) return x < t.x;
		else return y < t.y;
	}
}c[N],ans;

double getarea(circle& s,circle& t){
	return ((s.x - t.x) * (s.x - t.x) + (s.y - t.y) * (s.y - t.y));
}

int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%lf%lf",&c[i].x,&c[i].y);
	}
	for(int i = 0; i < n; i++){
		double maxarea = 0;
		for(int j = 0; j < n; j++){
			maxarea = max(maxarea,getarea(c[i],c[j]));
		}
		c[i].area = maxarea;
		if(c[i] < ans){
			ans = c[i];
		}
	}
	printf("%.2lf %.2lf\n%.2lf",ans.x,ans.y,ans.area);
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值