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\n");
			return 0;
		}
		r=dis(l-xx[1], yy[1]);
		if(r>=l+eps){
			printf("%f 0.0\n", l);
			return 0;
		}
		r=dis(xx[1], l-yy[1]);
		if(r>=l+eps){
			printf("0.0 %f\n", l);
			return 0;
		}
		r=dis(l-xx[1], l-yy[1]);
		if(r>=l+eps){
			printf("%f %f\n", l, l);
			return 0;
		}
		printf("GG\n");
	}
	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\n", x, y);
				break;
			}
		}
	}
	return 0;
}
posted @ 2018-05-21 19:04  poorpool  阅读(160)  评论(0编辑  收藏  举报