题意

PDF

分析

首先发现距离最短的直线肯定在凸包上面。

然后考虑直线一般方程\(Ax+By+C=0\),点\((x_0,y_0)\)到该直线的距离为

\[\frac{|Ax_0+By_0+C|}{\sqrt{A^2+B^2}}
\]

由于所有点在直线同侧,所以绝对值里面的符号相同,所以维护所有点\(x\)坐标和\(y\)坐标之和就行了。

时间复杂度\(O(T n \log n)\)

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll; struct Point
{
double x,y; Point(double x=0,double y=0)
:x(x),y(y){} bool operator<(co Point&rhs)
{
return x<rhs.x||(x==rhs.x&&y<rhs.y);
} bool operator==(co Point&rhs)
{
return x==rhs.x&&y==rhs.y;
}
};
typedef Point Vector; Vector operator-(co Point&A,co Point&B)
{
return Vector(A.x-B.x,A.y-B.y);
} double Cross(co Vector&A,co Vector&B)
{
return A.x*B.y-A.y*B.x;
} vector<Point> ConvexHull(vector<Point> p)
{
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end()); int n=p.size();
int m=0;
vector<Point>ch(n+1);
for(int i=0;i<n;++i)
{
while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
--m;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;--i)
{
while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
--m;
ch[m++]=p[i];
}
if(n>1)
--m;
ch.resize(m);
return ch;
} // (x2-x1)(y-y1) = (y2-y1)(x-x1) -> ax+by+c=0
void LineGeneralEquation(co Point&p1,co Point&p2,double&a,double&b,double&c)
{
a=p2.y-p1.y;
b=p1.x-p2.x;
c=-a*p1.x-b*p1.y;
} int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=read<int>();
for(int kase=1;kase<=T;++kase)
{
int n=read<int>();
vector<Point>P;
double sumx=0,sumy=0;
for(int i=0;i<n;++i)
{
int x=read<int>(),y=read<int>();
sumx+=x,sumy+=y;
P.push_back(Point(x,y));
}
vector<Point>ch=ConvexHull(P);
int m=ch.size();
double ans=1e9;
if(m<=2)
ans=0;
else
for(int i=0;i<m;++i)
{
double a,b,c;
LineGeneralEquation(ch[i],ch[(i+1)%m],a,b,c);
ans=min(ans,fabs(a*sumx+b*sumy+c*n)/sqrt(a*a+b*b));
}
printf("Case #%d: %.3lf\n",kase,ans/n);
}
return 0;
}

UVA11168 Airport的更多相关文章

  1. ios实用wifi分析仪——AirPort

    AirPort(wifi分析仪) android系统上免费的wifi分析仪很多,但是当我在AppStore上搜索时,找了半天也没找到想要的,后来还是问前辈才知道一款非常好用的app——AirPort, ...

  2. Airport(未解决。。。)

    Airport Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  3. HDU 5046 Airport(DLX反复覆盖)

    HDU 5046 Airport 题目链接 题意:给定一些机场.要求选出K个机场,使得其它机场到其它机场的最大值最小 思路:二分+DLX反复覆盖去推断就可以 代码: #include <cstd ...

  4. (中等) HDU 5046 Airport ,DLX+可重复覆盖+二分。

    Description The country of jiuye composed by N cites. Each city can be viewed as a point in a two- d ...

  5. word20170106在机场 At the airport有用的词和句子

    有用的词: airport terminal: 航站楼 domestic flight: 国内航班 international flight: 国际航班 checked luggage: 托运行李 c ...

  6. UVA - 11374 - Airport Express(堆优化Dijkstra)

    Problem    UVA - 11374 - Airport Express Time Limit: 1000 mSec Problem Description In a small city c ...

  7. UVA 11168 Airport(凸包)

    Airport [题目链接]Airport [题目类型]凸包 &题解: 蓝书274页,要想到解析几何来降低复杂度,还用到点到直线的距离公式,之后向想到预处理x,y坐标之和,就可以O(1)查到距 ...

  8. English Conversation – Checking in at an airport

    English Conversation – Checking in at an airport Share Tweet Share Tagged With: Ben Franklin Exercis ...

  9. 一颗可靠的时间胶囊:苹果AirPort Time Capsule测评

    http://sspai.com/24181/ 如何从 Time Machine 备份恢复数据? AirPort Time Capsule能轻松完成备份,自然也少不了方便地恢复备份.一般常见的恢复备份 ...

随机推荐

  1. iOS 10 系统 AVPlayer视频播放不了问题解决

    使用[AVAudioPlayer Play]时出现了异常... 由于xcode中设置了当所有异常出现时的断点,,解决办法是将all改为Objective-C: libc++abi.dylib`__cx ...

  2. Linux下MySQL 5.6.24的编译安装与部署

    MySQL 5.6正式版发布了,相对于5.5版本作出了不少改进,其源码安装配置方式也有所变化,本文根据实际操作,不断尝试,精确还原了安装的具体步骤. 在Linux下安装MySQL前,先确认卸载系统自带 ...

  3. 微信小程序选择器

  4. Mac下编译tesseract报错 DotProductAVX can't be used on Android

    因为我的mac是64位的,所以用32位编译,执行的时候肯定会出错的. 所以应该在 arch/simddetect.cpp中把这句# define X86_BUILD 1 注释掉,就可以了. 参考 ht ...

  5. Pandas注意事项&窍门

    警告和疑难意味着一个看不见的问题.在使用Pandas过程中,需要特别注意的地方. 与Pandas一起使用If/Truth语句 当尝试将某些东西转换成布尔值时,Pandas遵循了一个错误的惯例. 这种情 ...

  6. 10 个深恶痛绝的 Java 异常

    异常是 Java 程序中经常遇到的问题,我想每一个 Java 程序员都讨厌异常,一 个异常就是一个 BUG,就要花很多时间来定位异常问题. 今天,来列一下 Java 中经常遇到的前 10 个异常,排名 ...

  7. "Entity Framework数据插入性能追踪"读后总结

    园友莱布尼茨写了一篇<Entity Framework数据插入性能追踪>的文章,我感觉不错,至少他提出了问题,写了出来,引起了大家的讨论,这就是一个氛围.读完文章+评论,于是我自己也写了个 ...

  8. X2.5 添加自定义数据调用模块(简单方法)

    Discuz!X系列的diy功能还是相当不错的,在对其进行二次开发的过程中,或许需要加入新的数据调用模块,这样可以使你开发的功能模块也像原来的模块一样,只需要点点鼠标,填写一些简单的信息,就可以在各个 ...

  9. 【Java】final关键字

    1.final数据 (1)基本类型      数值恒定不变 (2)对象引用      引用恒定不变,初始化的时候指向一个对象后,无法改变为另一个对象,但是对象本身可以修改 2.final方法 可以把方 ...

  10. input预览上传图片

    html代码 <input type="file" name="file" id="file" > <img src=&q ...