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 ...
随机推荐
- Struts2 框架使用 核心以及其他详细配置
因为在使用SSH框架的过程,关于struts2的配置比较繁琐,所以做个总结. 一.导入并且关联其他XML 1. 因为在核心配置文件(Struts2.xml)中,如果存在很多需要配置的Action项 ...
- Runtime Services
Python Runtime Services — Python 3.7.2 documentation https://docs.python.org/3/library/python.html
- Maven基本介绍及安装
什么是Maven 是一个跨平台的项目管理工具. 跨平台是指它几乎可以在现有所有流行的操作系统中运行 maven不仅可以构建项目,还可以依赖管理和项目信息管理 Maven解决了什么问题 maven解决了 ...
- HTML5 自定义属性
先声明 HTML5的自定义属性浏览器支持性不太好 目前只有firefox6+和chrome浏览器支持 元素除了自带的属性外 另外也可以加自定义属性 不过需要在前面加上data- 下面举个例子 ...
- 10.2-uC/OS-III内部任务管理(任务状态)
1.任务状态 从用户的观点来看,任务可以是有 5种状态,见图 5-6.展示了任务状态间的转换关系. {休眠状态,就绪状态,运行状态,挂起状态,中断状态} (1).处于休眠状态的任务驻留于内存但未被uC ...
- dwr的ScriptSession和HttpSession分析
1.关于ScriptSession ScriptSession不会与HttpSession同时创建 当我们访问一个页面的时候,如果是第一次访问,会创建一个新的HttpSession,之后再访问的时候, ...
- 利用Linux的硬连接删除MySQL大文件
利用Linux的硬连接删除MySQL大文件 http://blog.csdn.net/wxliu1989/article/details/22895201 原理:硬链接基础当多个文件共同指向同一ino ...
- NYOJ 迷宫寻宝(一)
# include<iostream> # include<string> # include<string.h> # include<queue> # ...
- nginx 启动报错403
nginx 安装完成以后启动的时候报403, 网上找的答案是在配置文件nginx.conf里面加上 user root owner;这个要加在配置文件的第一行才行,否则还是会报错,配置文件截图为: 参 ...
- 帝国cms判断某一字段是否为空
<?php if(empty($navinfor[buy])) { ?> <? } else { ?> <h2 class="buy">< ...