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(凸包)的更多相关文章

  1. UVA 11168 - Airport - [凸包基础题]

    题目链接:https://cn.vjudge.net/problem/UVA-11168 题意: 给出平面上的n个点,求一条直线,使得所有的点在该直线的同一侧(可以在该直线上),并且所有点到该直线的距 ...

  2. UVA 11168 Airport(凸包+直线方程)

    题意:给你n[1,10000]个点,求出一条直线,让所有的点都在都在直线的一侧并且到直线的距离总和最小,输出最小平均值(最小值除以点数) 题解:根据题意可以知道任意角度画一条直线(所有点都在一边),然 ...

  3. 简单几何(数学公式+凸包) UVA 11168 Airport

    题目传送门 题意:找一条直线,使得其余的点都在直线的同一侧,而且使得到直线的平均距离最短. 分析:训练指南P274,先求凸包,如果每条边都算一边的话,是O (n ^ 2),然而根据公式知直线一般式为A ...

  4. uva 11168 - Airport

    凸包+一点直线的知识: #include <cstdio> #include <cmath> #include <cstring> #include <alg ...

  5. UVa 11168(凸包、直线一般式)

    要点 找凸包上的线很显然 但每条线所有点都求一遍显然不可行,优化方法是:所有点都在一侧所以可以使用直线一般式的距离公式\(\frac{|A* \sum{x}+B* \sum{y}+C*n|}{\sqr ...

  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

    题意: 平面上有n个点,求一条直线使得所有点都在直线的同一侧.并求这些点到直线的距离之和的最小值. 分析: 只要直线不穿过凸包,就满足第一个条件.要使距离和最小,那直线一定在凸包的边上.所以求出凸包以 ...

  8. uva 10065 (凸包+求面积)

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  9. UVA 11374 Airport Express SPFA||dijkstra

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. hdu6363 bookshelf 容斥+数列+数论gcd定理(也可以Möbius)

    #define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h&g ...

  2. vuex 的基本使用之Module

    Module 首先介绍下基本的组件化规则:你可以根据项目组件的划分来拆分 store,每个模块里管理着当前组件的状态以及行为,最后将这些模块在根 store 进行组合. const moduleA = ...

  3. ASP.NET MVC 计划任务(不使用外接程序,.net内部机制实现)

    在asp.net中要不使用其他插件的情况下只能使用定时器来检查, 并执行任务. 以下讲解步骤: 1. 在Global.asax 文件中作如下修改 1 2 3 4 5 6 7 8 9 10 11 voi ...

  4. regular expression (如何用Sed和正则表达式提取子字符串)

    echo "mv u3_yunying.war   u3_yunying.war_`date +%Y%m%d%H%M`" | sed "s/\(mv\) \(\w*.wa ...

  5. 图解Fiddler如何抓取Android数据包

    介绍Fiddler抓取Android数据包希望对大家的工作和学习有所帮助! 电脑开启wifi热点 首先在电脑上下载一个wifi软件,我这里用的是猎豹wifi,电脑开启wifi热点后,如下图所示:  设 ...

  6. 哨兵模式下,master选举关键点

    哨兵模式下的选举策略: 1:slave priority越低 ,优先级越高 2:1同等情况下,slave复制的数据越多优先级越高 3:2相同的条件下run id越小越容易被选举

  7. ECharts图形库

    ECharts图形库百度的项目,图形的创建也比较简单,直接引用Javascript即可 1,引入<script src="{{ url_for("static",f ...

  8. wait()函数的详细分析

    之前一直没太深入的去理解wait()函数,今天机缘巧合之前又看了看,发现之前没有真正的理解该函数. 众所周知,wait()函数一般用在父进程中等待回收子进程的资源,而防止僵尸进程的产生. (In UN ...

  9. xca自签发证书解决chrome浏览器证书不可信问题记录

    xca打开的界面 依次File, New DataBase,选择xdb文件保存路径,再输入密码 切换到Certificates页面,点击New Certificate 出现如下界面 因为要创建根证书, ...

  10. Java设计模式之模板模式及使用场景

    模板模式,顾名思义,就是通过模板拓印的方式. 定义模板,就是定义框架.结构.原型.定义一个我们共同遵守的约定. 定义了模板,我们的剩余工作就是对其进行充实.丰润,完善它的不足之处. 定义模板采用抽象类 ...