UVA 11168 Airport(凸包)
Airport
【题目链接】Airport
【题目类型】凸包
&题解:
蓝书274页,要想到解析几何来降低复杂度,还用到点到直线的距离公式,之后向想到预处理x,y坐标之和,就可以O(1)查到距离,还是很厉害的.
但我还是不知道为什么最后输出ans要除n?希望大佬看见可以评论告诉我一下.
&代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
struct Point {
double x,y;
Point(double x=0,double y=0):x(x),y(y) {}
};
typedef Point Vector;
Vector operator + (const Vector& A,const Vector& B) {return Vector(A.x+B.x , A.y+B.y);}
Vector operator - (const Vector& A,const Vector& B) {return Vector(A.x-B.x , A.y-B.y);}
bool operator < (const Point& a,const Point& b) {return a.x<b.x||(a.x==b.x&&a.y<b.y);}
bool operator == (const Point& a,const Point& b) {return a.x==b.x&&a.y==b.y;}
double Cross(const Vector&A,const Vector& B) {return A.x*B.y-A.y*B.x;}
Vector Rotate(const Vector& A,double a) {return Vector(A.x*cos(a)-A.y*sin(a) , A.x*sin(a)+A.y*cos(a));}
vector<Point> ConvexHull(vector<Point> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(), p.end()),p.end());
int n=p.size();
vector<Point> ch(n+1);
int m=0;
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;
}
int n,K;
int main() {
freopen("e:1.in","r",stdin);
int T; scanf("%d",&T);
while(T--) {
vector<Point> p;
scanf("%d",&n);
double sux=0,suy=0;
for(int i=0; i<n; i++) {
double x,y;
scanf("%lf%lf",&x,&y);
sux+=x,suy+=y;
p.push_back(Point(x,y));
}
vector<Point> te=ConvexHull(p);
int z=te.size();
te.push_back(te[0]);
double ans=1e15;
// printf("%f %f\n", sux,suy);
if(z<=2) {
ans=0;
}
else {
for(int i=1; i<te.size(); i++) {
double A=te[i].y-te[i-1].y,B=te[i-1].x-te[i].x,C=te[i].x*te[i-1].y-te[i-1].x*te[i].y;
ans=min(ans,fabs(A*sux+B*suy+C*n)/sqrt(A*A+B*B));
}
}
printf("Case #%d: %.3f\n", ++K, ans/n);
}
return 0;
}
UVA 11168 Airport(凸包)的更多相关文章
- UVA 11168 - Airport - [凸包基础题]
题目链接:https://cn.vjudge.net/problem/UVA-11168 题意: 给出平面上的n个点,求一条直线,使得所有的点在该直线的同一侧(可以在该直线上),并且所有点到该直线的距 ...
- UVA 11168 Airport(凸包+直线方程)
题意:给你n[1,10000]个点,求出一条直线,让所有的点都在都在直线的一侧并且到直线的距离总和最小,输出最小平均值(最小值除以点数) 题解:根据题意可以知道任意角度画一条直线(所有点都在一边),然 ...
- 简单几何(数学公式+凸包) UVA 11168 Airport
题目传送门 题意:找一条直线,使得其余的点都在直线的同一侧,而且使得到直线的平均距离最短. 分析:训练指南P274,先求凸包,如果每条边都算一边的话,是O (n ^ 2),然而根据公式知直线一般式为A ...
- uva 11168 - Airport
凸包+一点直线的知识: #include <cstdio> #include <cmath> #include <cstring> #include <alg ...
- UVa 11168(凸包、直线一般式)
要点 找凸包上的线很显然 但每条线所有点都求一遍显然不可行,优化方法是:所有点都在一侧所以可以使用直线一般式的距离公式\(\frac{|A* \sum{x}+B* \sum{y}+C*n|}{\sqr ...
- UVA - 11374 - Airport Express(堆优化Dijkstra)
Problem UVA - 11374 - Airport Express Time Limit: 1000 mSec Problem Description In a small city c ...
- UVa 11168 (凸包+点到直线距离) Airport
题意: 平面上有n个点,求一条直线使得所有点都在直线的同一侧.并求这些点到直线的距离之和的最小值. 分析: 只要直线不穿过凸包,就满足第一个条件.要使距离和最小,那直线一定在凸包的边上.所以求出凸包以 ...
- uva 10065 (凸包+求面积)
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- UVA 11374 Airport Express SPFA||dijkstra
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
随机推荐
- screen基本用法
当某些命令执行时间过长或者某些程序关闭shell后自动断开时,就能使用screen 1.安装yum -y install screen 2.输入screen命令进入screen控制台 3.输入scre ...
- [development][thrift] RPC框架 thrift
一: wiki:https://zh.wikipedia.org/wiki/Thrift 二: 来自IBM的介绍:https://www.ibm.com/developerworks/cn/java/ ...
- 深入hash
hash真的很好用,这些杂一点的知识点我觉得还是很有必要的,对还有离散化. 1<=N<=1,000,000,其它所有数据都在[0...1,000,000,000]范围内 看起来很简单一道水 ...
- 转:web.xml 配置中classpath: 与classpath*:的区别
原文链接:web.xml 配置中classpath: 与classpath*:的区别 引用自:http://blog.csdn.net/wxwzy738/article/details/1698393 ...
- jquery中$.get()提交和$.post()提交的区别
相同点:都是异步请求的方式来获取服务器端的数据: 异同点: 1.请求方式不同:$.get()方法使用 GET 方法来进行异步请求的:$.post()方法使用POST方法来进行异步请求的: 2.参数传递 ...
- iis子站点
在iis已有的站点下可以继续添加”应用程序”,就构成子站点:需要访问子站点app下的程序,只想在controller/action前,加个app就行,即app/controller/action 这样 ...
- 如何将wordpress所有文章批量改为已发布状态
用wordpress建站的一个好处就是bd站长工具平台上有数据结构插件,可以认为bd默认支持wp发展,另外一种建站程序是discuz.我们在用wordpress发布文章时,特别是那种多用户投稿的文章一 ...
- web应用1
阅读内容 一.web应用 二.web协议 三.web框架 四.补充知识 回到顶部 一.web应用 二.web协议 三.web框架 四.补充知识 五.补充知识
- 转换区别json
private Date EndDate ; private Instant xxxxdate; private LocalDateTime localDateTime; public static ...
- struct模块
struct模块的作用是将数据长度转换成固定长度的内容 一般默认是4个字节 需要注意的是,struct模块是有缺点的,就是struct的int类型或别的类型不是无限制的.当整数大于一定值后,会失败,即 ...