题目链接:http://codeforces.com/gym/102006/problem/I
题意:
一个机器人要移动n次,每次移动的路径已知,告诉你桌子的大小和机器人的大小,问你不让机器人移动出桌子的初始位置在哪里。
做法:
因为没有完全确定就不说了 留个板子就好、
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-6;
const double Pi=acos(-1.0);
const int maxn=255;
struct node{
double x,y;
node(){}
node(double x,double y):x(x),y(y){}
} P[maxn],c;
int n;
typedef node Vector;
int dcmp(double x)
{
if (fabs(x)<eps) return 0;
else if (x<0) return -1;
else return 1;
}
Vector operator + (Vector a, Vector b){
return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Vector a, Vector b){
return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector a, double p){
return Vector(a.x*p, a.y*p);
}
Vector operator / (Vector a, double p){
return Vector(a.x / p, a.y / p);
}
bool operator == (const node &a, const node &b){
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Vector a, Vector b){//内积
return a.x*b.x + a.y*b.y;
}
double Length(Vector a){//模
return sqrt(Dot(a, a));
}
double Angle(Vector a, Vector b){//夹角,弧度制
return acos(Dot(a, b) / Length(a) / Length(b));
}
double Cross(Vector a, Vector b){//外积
return a.x*b.y - a.y*b.x;
}
Vector Rotate(Vector a, double rad){//逆时针旋转
return Vector(a.x*cos(rad) - a.y*sin(rad), a.x*sin(rad) + a.y*cos(rad));
}
double Distance(node a, node b){//两点间距离
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
double Area(node a, node b, node c){//三角形面积
return fabs(Cross(b - a, c - a) / 2);
}
double lenth(node a) {return sqrt(Dot(a,a));}
node rotate(node a,double t) //向量旋转
{
return node(a.x*cos(t)-a.y*sin(t),a.x*sin(t)+a.y*cos(t));
}
node jiao(node p,node v,node q,node w)
//p+tv
//q+tw
{
node u=p-q;
double t=Cross(w,u)/Cross(v,w);
return p+v*t;
}
node get_c(node a,node b,node c)
{
node p=(a+b)/2; //ad中点
node q=(a+c)/2; //ac中点
node v=rotate(b-a,Pi/2.0),w=rotate(c-a,Pi/2.0); //中垂线的方向向量
if (dcmp(Cross(v,w))==0) //平行
{
if (dcmp(Length(a-b)+Length(b-c)-Length(a-c))==0)
return (a+c)/2;
if (dcmp(Length(b-a)+Length(a-c)-Length(b-c))==0)
return (b+c)/2;
if (dcmp(Length(a-c)+Length(c-b)-Length(a-b))==0)
return (a+b)/2;
}
return jiao(p,v,q,w);
}
void min_circular(){
random_shuffle(P+1,P+n+1); //随机化
double r;
c=P[1],r=0;
//c 圆心
//r 半径
for (int i=2;i<=n;i++)
if (dcmp(lenth(c-P[i])-r)>0) //不在圆内
{
c=P[i],r=0;
for (int j=1;j<i;j++)
if (dcmp(lenth(c-P[j])-r)>0)
{
c=(P[i]+P[j])/2.0;
r=lenth(c-P[i]);
for (int k=1;k<j;k++)
if (dcmp(lenth(c-P[k])-r)>0)
{
c=get_c(P[i],P[j],P[k]);
r=lenth(c-P[i]);
}
}
}
}
int main(){
freopen("robots.in","r",stdin);
int t;
cin>>t;
while(t--){
double R,r,xx,yy;
scanf("%d%lf%lf",&n,&R,&r);
P[1]=node(0,0);
n++;
for(int i=2;i<=n;i++){
scanf("%lf%lf",&xx,&yy);
P[i]=P[i-1]+node(xx,yy);
}
min_circular();
printf("%.8f %.8f\n",-c.x,-c.y);
}
}