UVA11168 Airport
题意
分析
首先发现距离最短的直线肯定在凸包上面。
然后考虑直线一般方程\(Ax+By+C=0\),点\((x_0,y_0)\)到该直线的距离为
\]
由于所有点在直线同侧,所以绝对值里面的符号相同,所以维护所有点\(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的更多相关文章
- ios实用wifi分析仪——AirPort
AirPort(wifi分析仪) android系统上免费的wifi分析仪很多,但是当我在AppStore上搜索时,找了半天也没找到想要的,后来还是问前辈才知道一款非常好用的app——AirPort, ...
- Airport(未解决。。。)
Airport Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 5046 Airport(DLX反复覆盖)
HDU 5046 Airport 题目链接 题意:给定一些机场.要求选出K个机场,使得其它机场到其它机场的最大值最小 思路:二分+DLX反复覆盖去推断就可以 代码: #include <cstd ...
- (中等) 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 ...
- word20170106在机场 At the airport有用的词和句子
有用的词: airport terminal: 航站楼 domestic flight: 国内航班 international flight: 国际航班 checked luggage: 托运行李 c ...
- UVA - 11374 - Airport Express(堆优化Dijkstra)
Problem UVA - 11374 - Airport Express Time Limit: 1000 mSec Problem Description In a small city c ...
- UVA 11168 Airport(凸包)
Airport [题目链接]Airport [题目类型]凸包 &题解: 蓝书274页,要想到解析几何来降低复杂度,还用到点到直线的距离公式,之后向想到预处理x,y坐标之和,就可以O(1)查到距 ...
- English Conversation – Checking in at an airport
English Conversation – Checking in at an airport Share Tweet Share Tagged With: Ben Franklin Exercis ...
- 一颗可靠的时间胶囊:苹果AirPort Time Capsule测评
http://sspai.com/24181/ 如何从 Time Machine 备份恢复数据? AirPort Time Capsule能轻松完成备份,自然也少不了方便地恢复备份.一般常见的恢复备份 ...
随机推荐
- 验证环境中的program为什么必须是automatic
最近在项目中,发现验证环境中的顶层的program(一般将program作为验证环境的入口),都是automatic的. 其实Program默认是static的,那么为什么需要把验证环境做成autom ...
- Java实验五网络编程与安全
实验五 网络编程与安全 实验准备 博客 活动一 两人一组结对编程: 0. 参考http://www.cnblogs.com/rocedu/p/6766748.html#SECDSA 1. 结对实现中缀 ...
- [nowcoder]因数个数和
链接:https://www.nowcoder.com/acm/contest/158/A 考虑每个数对答案的贡献,所以答案就是$\sum_{i=1}^{n}{\lfloor\frac{n}{i}\r ...
- Java JDBC概要总结一(基本操作和SQL注入问题)
JDBC定义: JDBC(Java DataBase Connectivity,java数据库连接)是一种用于执行SQL语句的Java API.JDBC是Java访问数据库的标准规范,可以为不同的关系 ...
- 网易编程题——Fibonacci数列
题目描述 Fibonacci数列是这样定义的: F[0] = 0 F[1] = 1 for each i ≥ 2: F[i] = F[i-1] + F[i-2] 因此,Fibonacci数列就形如:0 ...
- nginx+tomcat网页动静分离配置
1.环境描述 nginx server (Proxy):192.168.1.135(作为代理服务器)WEB server1: 192.168.1.138(使用tomcat作为web容器)WEB ser ...
- nagios无法载入静态资源
使用nginx+nagios无法载入静态资源,看了下url中增加了一个/nagios 查看是/usr/local/nagios/etc/cgi.conf中url_html_path=/nagios 将 ...
- spring boot项目获取application配置文件参数的两种方式
前言:了解过spring boot这个技术的,应该知道spring boot的核心配置文件application.properties,当然也可以通过注解自定义配置文件**.properties的信息 ...
- Ambari Views的自定义
下载ambari源码, ambari-views/examples/ 下面有很多例子,直接编译是不会成功的, 因为每一个例子项目都需要一个依赖 <dependency> <group ...
- bzoj 3884 上帝与集合的正确用法 指数循环节
3884: 上帝与集合的正确用法 Time Limit: 5 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 根据一些 ...