题意

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. shell脚本 入门 —— 符号篇

    shell Shell就是一个命令行解释器,它的作用是解释执行用户的命令,用户输入一条命令,Shell就解释执行一条,这种方式称为交互式(Interactive). Shell还有一种执行命令的方式称 ...

  2. 学习笔记1126 - Fib的计算方法,降低了时间复杂度

    #include <stdio.h> #include <stdlib.h> #define NUM 10 //如果NUM很大的话,应该申请的动态内存要用long类型吧? in ...

  3. Pytorch实现卷积神经网络CNN

    Pytorch是torch的Python版本,对TensorFlow造成很大的冲击,TensorFlow无疑是最流行的,但是Pytorch号称在诸多性能上要优于TensorFlow,比如在RNN的训练 ...

  4. [BZOJ2730]矿场搭建

    Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一 ...

  5. hibernate——第一次简单的使用

    提前有jdk.mysql.hibernate必须jar包.mysql连接jar包 mysql中的表 Java中的bean,User类 package com.xiaostudy.demo; publi ...

  6. java web 实体类生成

    工具下载地址:https://download.csdn.net/download/g342105676/10813246

  7. springmvc学习(2)

    SpringMvc是最主流的MVC框架之一. Spring3.0后全面超越Struts2,成为最优先的MVC框架 SpringMVC通过一套MVC注解,让POJO成为处理请求的控制器,而无须实现任何借 ...

  8. 卸载oracle11g

    完全卸载oracle11g步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->Oracle - OraHome ...

  9. leetcode 2SUM

         ; i < numbers.size(); ++i){             ; i < v.size(); i++){             ; j < v.size ...

  10. html5新增语义化标签

    注意:body.section.nav 需要h1-h6. div.header则不需要. 1):<article> 显示一个独立的文章内容. 例如一篇完整的论坛帖子,一则网站新闻,一篇博客 ...