luoguT30204 偷上网

(n=1) 时特判四角,其余时刻圆的面积和必小于正方形面积,随机点出来判断就行了。

stm 随机算法……

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int n;
double l, xx[15], yy[15];
const double eps=1e-6;
double dis(double x, double y){
	return sqrt(x*x+y*y);
}
int main(){
	srand(time(NULL));
	cin>>n>>l;
	for(int i=1; i<=n; i++)
		cin>>xx[i]>>yy[i];
	if(n==1){
		double r=dis(xx[1], yy[1]);
		if(r>=l+eps){
			printf("0.0 0.0
");
			return 0;
		}
		r=dis(l-xx[1], yy[1]);
		if(r>=l+eps){
			printf("%f 0.0
", l);
			return 0;
		}
		r=dis(xx[1], l-yy[1]);
		if(r>=l+eps){
			printf("0.0 %f
", l);
			return 0;
		}
		r=dis(l-xx[1], l-yy[1]);
		if(r>=l+eps){
			printf("%f %f
", l, l);
			return 0;
		}
		printf("GG
");
	}
	else{
		while(true){
			double x=rand(), y=rand();
			x/=2147483647;
			y/=2147483647;
			x*=l;
			y*=l;
			bool flag=true;
			for(int i=1; i<=n; i++)
				if(dis(xx[i]-x,yy[i]-y)<l/n+eps)
					flag = false;
			if(flag){
				printf("%.12f %.12f
", x, y);
				break;
			}
		}
	}
	return 0;
}
原文地址:https://www.cnblogs.com/poorpool/p/9068804.html