思路:先考虑在D高度的最小圆覆盖,再一层一层往下走时,可以保证圆心与最开始的圆相同的时候答案是最优的。

时间复杂度O(n)

有一个坑点,就是我用了srand(time(NULL))就T了,RP太差了。。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<time.h>
const double eps=1e-;
const double inf=1e60;
const double Pi=acos(-);
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}p[],O;
struct Line{
Point s,e;
Line(){}
Line(Point s0,Point e0):s(s0),e(e0){}
};
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
Point operator +(Point p1,Point p2){
return Point(p1.x+p2.x,p1.y+p2.y);
}
Point operator *(Point p,double x){
return Point(p.x*x,p.y*x);
}
Point operator /(Point p,double x){
return Point(p.x/x,p.y/x);
}
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
double sqr(double x){
return x*x;
}
double dis(Point p1){
return sqrt(sqr(p1.x)+sqr(p1.y));
}
double dis(Point p1,Point p2){
return dis(p1-p2);
}
int n;
double cost[],D,R;
int H;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
Point inter(Line p1,Line p2){
double k1=(p2.e-p1.s)*(p1.e-p1.s);
double k2=(p1.e-p1.s)*(p2.s-p1.s);
double t=(k2)/(k1+k2);
double x=p2.s.x+(p2.e.x-p2.s.x)*t;
double y=p2.s.y+(p2.e.y-p2.s.y)*t;
return Point(x,y);
}
Point turn(Point p,double ang){
double Cos=cos(ang);
double Sin=sin(ang);
double x=Cos*p.x-Sin*p.y;
double y=Cos*p.y+Sin*p.x;
return Point(x,y);
}
Point calc(Point p1,Point p2,Point p3){
Point a=(p1+p2)/2.0;
Point b=(p2+p3)/2.0;
Point A=turn(p2-p1,Pi/2.0)+a;
Point B=turn(p3-p2,Pi/2.0)+b;
return inter(Line(a,A),Line(b,B));
}
int main(){
//srand(time(NULL));
int DD;
n=read();H=read();scanf("%lf",&R);DD=read();
D=DD;
for (int i=;i<=H;i++) cost[i]=read();
for (int i=;i<=n;i++) p[i].x=read(),p[i].y=read();
for (int i=;i<=n;i++)
std::swap(p[rand()%n+],p[rand()%n+]);
O=p[];double r=;
for (int i=;i<=n;i++)
if (dis(O,p[i])>r+eps){
O=p[i];r=;
for (int j=;j<i;j++)
if (dis(O,p[j])>r+eps){
O=(p[i]+p[j])/2.0;
r=dis(O,p[j]);
for (int k=;k<j;k++)
if (dis(O,p[k])>r+eps){
O=calc(p[i],p[j],p[k]);
r=dis(O,p[k]);
}
}
}
double ans=inf,rr,xx,yy;
int hh;
H=std::min(H,DD);
for (int i=;i<=H;i++){
double sxr=std::max(R,r-sqrt(sqr(D)-sqr((double)i)));
if (sxr*cost[i]<ans){
ans=sxr*cost[i];
rr=sxr;
xx=O.x;
yy=O.y;
hh=i;
}
}
printf("%.10f\n",ans);
printf("%.10f %.10f %d %.10f\n",xx,yy,hh,rr);
}

XJOI网上同步测试DAY14 T2的更多相关文章

  1. XJOI网上同步测试DAY14 T3

    思路:tarjan把桥找出来,然后缩点,注意这里的缩点是:如果两个点之间的连边不是桥,那么就把他们缩起来,然后用一个lct维护,对于每个询问,如果官道连接的是两个联通块的话,就把他们连起来,否则我们就 ...

  2. XJOI网上同步测试DAY14 T1

    思路:线段树维护最短路 #include<cstdio> #include<cmath> #include<iostream> #include<algori ...

  3. XJOI网上同步训练DAY6 T2

    思路:记得FJ省队集训好像有过这题,可是我太弱了,根本不懂T_T #include<cstdio> #include<iostream> #include<cmath&g ...

  4. XJOI网上同步训练DAY3 T2

    考试的时候已经想出来怎么做了,但是没有时间打了T_T 思路:我们考虑将询问以lim排序,然后树链剖分,把边作为线段树的节点,然后随着询问lim的增大,改变线段树中节点的信息,然后每次询问我们用树链剖分 ...

  5. XJOI网上同步训练DAY2 T2

    [问题描述] 火车司机出秦川跳蚤国王下江南共价大爷游长沙.每个周末勤劳的共价大爷都会开车游历长沙市. 长沙市的交通线路可以抽象成为一个

  6. XJOI网上同步训练DAY1 T2

    思路:似曾相识?...见http://www.cnblogs.com/qzqzgfy/p/5266874.html 一看时限还是4s!,于是就开开心心地打了70%的分,就是用容斥原理,就可以n^3解决 ...

  7. XJOI网上同步训练DAY6 T1

    思路:考试的时候直接想出来了,又有点担心复杂度,不过还是打了,居然是直接A掉,开心啊. 我们发现,Ai<=7,这一定是很重要的条件,我们考虑状态压缩,去枚举路径中出现了哪些数字,然后我们把原来n ...

  8. XJOI网上同步训练DAY5 T1

    思路:考虑得出,最终的集合一定是gcd=1的集合,那么我们枚举n个数中哪个数必须选,然后把它质因数分解,由于质数不会超过9个,可以状态压缩,去得出状态为0的dp值就是答案. #include<c ...

  9. XJOI网上同步训练DAY5 T3

    就是对于一个数,我们去考虑把t*****减到(t-1)9999*的代价. #include<cstdio> #include<cmath> #include<algori ...

随机推荐

  1. 001_python变量命名规范(待实践一遍)

    参考: http://blog.sina.com.cn/s/blog_62f28d560100xv85.html https://my.oschina.net/leejun2005/blog/3871 ...

  2. div+css 圆角加阴影

    .test{ display: inline-block; padding: 5px 10px 6px; text-decoration: none; border-radius: 5px; -moz ...

  3. DTN学习的一些有用链接

    1.DTN研究组,该网站提供了一些代码,有NS2上的实现,也有用java实现的源码. http://www.dtnrg.org/wiki/Code 2.DTN实现的另一个版本,与ONE比较,目前还没用 ...

  4. yii2使用Gii生成代码

    本章节将介绍怎样使用 Gii 去自己主动生成 Web 网站经常使用功能的代码.使用 Gii 生成代码很easy,仅仅要依照 Gii 页面上的介绍输入正确的信息就可以. 贯穿本章节,你将会学到: 在你的 ...

  5. Two-Phase-Commit for Distributed In-Memory Caches--reference

    Part I reference from:http://gridgain.blogspot.kr/2014/09/two-phase-commit-for-distributed-in.html 2 ...

  6. 《C专家编程》之一

    一.解决函数返回指针的几种方法 1. 返回一个指向字符串常量的指针. 例子: char* func() { rturn "Only work for simple strings" ...

  7. Lombok介绍及使用方法

    lombok简介 lombok是暑假来到公司实习的时候发现的一个非常好用的小工具,刚见到的时候就感觉非常惊艳,有一种相见恨晚的感觉,用了一段时间之后感觉的确挺不错,所以特此来推荐一下. lombok的 ...

  8. Myeclipse中点(.)不出来方法或者属性?

  9. C#总结项目《影院售票系统》编写总结三

    昨天总结了动态绘制控件.票类型的切换以及数据在窗体中的展现.今天继续总结,自己喜欢的就去做吧,让别人说去吧,省的自己再留下什么后悔遗憾,噢耶,加油! 今天总结项目中最核心的部分--购票.座位颜色状态的 ...

  10. C++线性序列容器<vector>简单总结

    C++线性序列容器<vector>简单总结 vector是一个长度可变的数组,使用的时候无须声明上限,随着元素的增加,Vector的长度会自动增加:Vector类提供额外的方法来增加.删除 ...