记录编号 230468 评测结果 AAAAAAAA
题目名称 [CEOI1999][POJ1379]逃离陷阱 最终得分 100
用户昵称 GravatarSatoshi 是否通过 通过
代码语言 C++ 运行时间 0.403 s
提交时间 2016-02-22 06:07:44 内存使用 0.25 MiB
显示代码纯文本
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define N 1110
using namespace std;
typedef long double ld;
ifstream cin("runaway.in");
ofstream cout("runaway.out");
int n;
ld ansx,ansy,r,X[120],Y[120],R[120],INF=999999999;
ld XO,YO;
class point
{
public:
	ld x,y;
	void make(ld a,ld b)
	{
		x=a;
		y=b;
	}
	void print()
	{
		cout<<x<<' '<<y<<endl;
	}
}P[N],dir[9];
ld operator *(point a,point b)
{
	ld solo;
	solo=a.x*b.x+a.y*b.y;
	return solo;
}
void print(ld x)
{
	cout <<setprecision(1) <<std::fixed <<x;
}
point operator -(point a,point b)
{
	point c;
	c.x=a.x-b.x;
	c.y=a.y-b.y;
	return c;
}
point operator +(point a,point b)
{
	point c;
	c.x=a.x+b.x;
	c.y=a.y+b.y;
	return c;
}
point operator *(point a,ld b)
{
	point c;
	c.x=a.x*b;
	c.y=a.y*b;
	return c;
}
ld len(point x){return sqrt(x*x);}
ld dis(point x)
{
	int i;
	point y;
	ld sum=INF,temp=0;
	for(i=1;i<=n;i++)
	{
		y=x-P[i];
		temp=len(y);
		//cout<<temp<<endl;
		if(temp<sum)sum=temp;
	}
	//cout<<sum<<endl;
	return sum;
}
void init()
{
	dir[1].make(0,1);
	dir[2].make(1,0);
	dir[3].make(0,-1);
	dir[4].make(-1,0);
	dir[5].make(1,-1);
	dir[6].make(-1,1);
	dir[7].make(1,1);
	dir[8].make(-1,-1);
	srand(time(NULL));
}
void ansout()
{
	cout<<"The safest point is (";
		print(ansx);
		cout<<',';
		print(ansy);
		cout<<").";
		//print(r);
		cout<<endl;
}
bool law(point O)
{
	if(O.x>=0&&O.x<=XO&&O.y>=0&&O.y<=YO)return 1;
	return 0;
}
void work(point O)
{
	ld step,ha,temp,base,basex,basey;
	point U,V,T;
	int i,k;
	U=T=O;
	r=0;
	base=6.5;
	for(k=1;k<=100;k++)
	{
		r=0;
		R[k]=0;
		U=O;
	for(step=100000;step>=0.0001;step/=base)
	{
		U=T;
		//out<<step<<endl;
		for(i=1;i<=8;i++)
		{
			V=U+dir[i]*step;
			if(!law(V))continue;
			temp=dis(V);
			if(temp>R[k])
			{
				X[k]=V.x;
				Y[k]=V.y;
				R[k]=temp;
				T=V;
			}
		}
	}
	base-=0.05;
	}
	r=0;
	for(k=1;k<=100;k++)
	{
		if(R[k]>r)
		{
			ansx=X[k];
			ansy=Y[k];
			r=R[k];
		}
	}
	//ansout();
	/*for(k=1;k<=1;k++)
	{
	U.make(ansx,ansy);
	for(step=-5;step<=5;step+=0.1)
	{
		for(ha=-5;ha<=5;ha+=0.1)
		{
			V.x=U.x+step;
			V.y=U.y+ha;
			temp=dis(V);
			if(r>temp)
			{
				ansx=V.x;
				ansy=V.y;
				r=temp;
			}
		}
	}
	U.make(ansx,ansy);
	for(step=-0.5;step<=0.5;step+=0.01)
	{
		for(ha=-0.5;ha<=0.5;ha+=0.01)
		{
			V.x=U.x+step;
			V.y=U.y+ha;
			temp=dis(V);
			if(r>temp)
			{
				ansx=V.x;
				ansy=V.y;
				r=temp;
			}
		}
	}
	U.make(ansx,ansy);
	for(step=-0.05;step<=0.05;step+=0.001)
	{
		for(ha=-0.05;ha<=0.05;ha+=0.001)
		{
			V.x=U.x+step;
			V.y=U.y+ha;
			temp=dis(V);
			if(r>temp)
			{
				ansx=V.x;
				ansy=V.y;
				r=temp;
			}
		}
	}
	}*/
}

int main()
{
	int T,i;
	point Q;
	init();
	T=1;
	while(T--)
	{
		cin>>XO>>YO>>n;
		for(i=1;i<=n;i++)cin>>P[i].x>>P[i].y;
		work(P[1]);
		ansout();
	}
	return 0;
}