题意

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. Python3.x:日期库dateutil简介

    Python3.x:日期库dateutil简介 安装 pip install python-dateutil 关于parser #字符串可以很随意,可以用时间日期的英文单词,可以用横线.逗号.空格等做 ...

  2. SpringBoot Bean作用域

    Bean在一般容器中都存在以下2种作用域: singleton 默认值,IoC容器只存在单例 prototype 每当从IoC容器中取出一个Bean,则创建一个新的Bean 在Web容器中存在4种作用 ...

  3. m2eclipse插件——添加依赖不显示搜索结果

    使用Eclipse,安装m2eclipse插件之后,选中Maven项目的pom文件,添加依赖,点击“Add Dependency”的时候,输入要检索的jar包名称,search result却一直为空 ...

  4. Caffe2——C++ 预测(predict)Demo

    因为最近入坑Caffe2,它最近还一直在更新,所以坑比较多,官方也只给出了python的demo,C++的暂时还找不到,有也只有一个简单版的,不够用,所以就总结了一下,结合网上和自己的实践,整理了一下 ...

  5. 一位交易巨匠的十年心得:如何使用MACD判断后期趋势,把握买卖点

    高手与散户的区别在哪里? 高手与散户的区别在哪里,从宏观上讲:一流高手用境界,二流高手用趋势,三流高手用技术,普通散户用迷糊.最高境界的人在讲心境如何,什么也不看,只用感觉就能炒好股赚钱.我说一流高手 ...

  6. ASCII_02_扩展

    1.来自“http://www.360doc.com/content/10/1007/22/3775569_59187136.shtml” 2. 3. 4. 5.

  7. phpstrom ctrl+s无法上传的问题 解决

    首先这个不教你怎么配置同步FTP,这个教程网上太多了. 主要是配置好了上传,上传的好好的,突然某一天不能上传了,或者配置好了上传不了. 我遇到的问题是,如果你没有点击Use this server a ...

  8. 英语发音规则---A字母

    英语发音规则---A字母 一.总结 一句话总结:本文所有//的音标为英音音标,[]的音标为美音音标 1.A在开音节中发/eɪ/ [e]? age /eɪdʒ/ [edʒ] 年龄 ape /eɪp/ [ ...

  9. CheckBox复选框控件

    CheckBox复选框控件 一.简介 1. 2.类结构图 二.CheckBox复选框控件使用方法 这里是使用java代码在LinearLayout里面添加控件 1.新建LinearLayout布局 2 ...

  10. Java class、Object、Class 的区别

    Java的对象模型中: 所有的类都是Class类的实例,Object是类,那么Object也是Class类的一个实例. 所有的类都最终继承自Object类,Class是类,那么Class也继承自Obj ...