记录编号 |
195340 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
约翰的电网 |
最终得分 |
100 |
用户昵称 |
mikumikumi |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.088 s |
提交时间 |
2015-10-18 18:16:50 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int SIZEN=160,INF=0x7fffffff/2;
const double zero=1e-1;
int N;
double minx=INF,miny=INF,maxx=0,maxy=0;
double mi=INF,ansx=-1,ansy=-1;
class poi
{
public:
double x,y;
void input()
{
scanf("%lf%lf",&x,&y);
x*=10,y*=10;
minx=min(minx,x);
maxx=max(maxx,x);
miny=min(miny,y);
maxy=max(maxy,y);
}
bool operator > (poi b)
{
if(x==b.x) return y>b.y;
return x>b.x;
}
};
class miku
{
public:
poi A,B;
bool type;//0代表竖
void input()
{
A.input();
B.input();
if(A.x==B.x) type=1;
else type=0;
if(A>B) swap(A,B);
}
double dist(poi a,poi b)
{
double temx=b.x-a.x,temy=b.y-a.y;
return sqrt(temx*temx+temy*temy);
}
double dist(double xd,double yd)
{
poi n;
n.x=xd;n.y=yd;
if(type==1)
{
if(A.y<=yd&&yd<=B.y) return abs(xd-A.x);
else if(B.y<yd) return dist(B,n);
else if(yd<A.y) return dist(A,n);
}
else
{
if(A.x<=xd&&xd<=B.x) return abs(yd-A.y);
else if(B.x<xd) return dist(B,n);
else if(xd<A.x) return dist(A,n);
}
cout<<"fuck"<<endl;
return 0;
}
}P[SIZEN];
void read()
{
scanf("%d",&N);
for(int i=1;i<=N;i++) P[i].input();
}
void work()
{
double now=10;
double dis=0;
double nminx=minx,nminy=miny,nmaxx=maxx,nmaxy=maxy;
while(now>zero)
{
poi st,ed;
st.x=nminx,st.y=nminy;ed.x=nmaxx;ed.y=nmaxy;
double i=st.x;
//cout<<nminx<<" "<<nminy<<" "<<nmaxx<<" "<<nmaxy<<endl;
//cout<<ansx<<" "<<ansy<<endl;
while(ed.x+zero+now>i)
{
double j=st.y;
while(ed.y+zero+now>j)
{
dis=0;
for(int k=1;k<=N;k++)
{
dis+=P[k].dist(i,j);
//if(i==10&&j==16) cout<<P[k].type<<" "<<P[k].A.x<<" "<<P[k].A.y<<" "<<P[k].B.x<<" "<<P[k].B.y<<" "<<P[k].dist(i,j)<<endl;
}
if(dis<mi)
{
mi=dis;
ansx=i;ansy=j;
nminx=i-now;nminy=j-now;nmaxx=i+now;nmaxy=j+now;
}
j+=now;
//cout<<i<<" "<<j<<endl;
}
i+=now;
}
now/=10.0;
}
mi/=10.0;ansx/=10.0;ansy/=10.0;
printf("%.1lf %.1lf %.1lf\n",ansx,ansy,mi);
}
int main()
{
freopen("fence3.in","r",stdin);
freopen("fence3.out","w",stdout);
read();
work();
return 0;
}