uva 11168 - Airport
凸包+一点直线的知识;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define eps 1e-9
using namespace std;
const double pi = acos(-); int dcmp(double x)
{
return fabs(x) < eps ? : (x > ? : -);
} struct Point
{
double x;
double y; Point(double x = , double y = ):x(x), y(y) {} bool operator < (const Point& e) const
{
return dcmp(x - e.x) < || (dcmp(x - e.x) == && dcmp(y - e.y) < );
} bool operator == (const Point& e) const
{
return dcmp(x - e.x) == && dcmp(y - e.y) == ;
}
}; typedef Point Vector; Vector operator + (Point A, Point B)
{
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B)
{
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Point A, double p)
{
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p)
{
return Vector(A.x / p, A.y / p);
} double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
Point rotate(Point a,double ang){return Point(a.x*cos(ang)-a.y*sin(ang),a.x*sin(ang)+a.y*cos(ang));}
int convexhull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for(int i=;i<n;i++)
{
while(m>&&cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--)
{
while(m>k&&cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
}
Point p[],ch[]; int main()
{
int t,n,ca=;
scanf("%d",&t);
while(t--)
{
double sumx=;
double sumy=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
sumx+=p[i].x;
sumy+=p[i].y;
}
printf("Case #%d: ",ca++);
double mi=99999999999.0;
int m=convexhull(p,n,ch);
for(int i=;i<m;i++)
{
double a=-ch[(i+)%m].y+ch[i].y;
double b=ch[(i+)%m].x-ch[i].x;
double c=ch[i].x*ch[(i+)%m].y-ch[i].y*ch[(i+)%m].x;
double d=fabs(a*sumx+b*sumy+c*n)/sqrt(a*a+b*b);
mi=min(mi,d);
}
printf("%.3lf\n",n>?mi/n:);
}
return ;
}
uva 11168 - Airport的更多相关文章
- UVA 11168 Airport(凸包)
Airport [题目链接]Airport [题目类型]凸包 &题解: 蓝书274页,要想到解析几何来降低复杂度,还用到点到直线的距离公式,之后向想到预处理x,y坐标之和,就可以O(1)查到距 ...
- UVA 11168 Airport(凸包+直线方程)
题意:给你n[1,10000]个点,求出一条直线,让所有的点都在都在直线的一侧并且到直线的距离总和最小,输出最小平均值(最小值除以点数) 题解:根据题意可以知道任意角度画一条直线(所有点都在一边),然 ...
- 简单几何(数学公式+凸包) UVA 11168 Airport
题目传送门 题意:找一条直线,使得其余的点都在直线的同一侧,而且使得到直线的平均距离最短. 分析:训练指南P274,先求凸包,如果每条边都算一边的话,是O (n ^ 2),然而根据公式知直线一般式为A ...
- UVA 11168 - Airport - [凸包基础题]
题目链接:https://cn.vjudge.net/problem/UVA-11168 题意: 给出平面上的n个点,求一条直线,使得所有的点在该直线的同一侧(可以在该直线上),并且所有点到该直线的距 ...
- 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 11374 Airport Express SPFA||dijkstra
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11374 Airport Express(最短路)
最短路. 把题目抽象一下:已知一张图,边上的权值表示长度.现在又有一些边,只能从其中选一条加入原图,使起点->终点的距离最小. 当加上一条边a->b,如果这条边更新了最短路,那么起点st- ...
- UVA - 11374 Airport Express (Dijkstra模板+枚举)
Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express ...
随机推荐
- iOS UIKit:TableView之编辑模式(3)
一般table view有编辑模式和正常模式,当table view进入编辑模式时,会在row的左边显示编辑和重排控件,如图 42所示的编辑模式时的控件布局:左边的editing control有表 ...
- javabean对象要实现的接口们和要重写的方法们
在使用list集合的时候,什么也不用. 原因:list允许存储重复的元素. 在使用set集合的时候,要重写,equals()方法 和 hashCode() 方法. 愿意:set集合 不允许存放相同的元 ...
- 通用的 makefile 小工具分享 - Easymake 使用说明
Easymake 使用说明 介绍 Easymake 是一个在linux系统中 C/C++ 开发的通用 makefile.在一个简单的 C/C++ 程序中使用 easymake,你甚至可以不写一行 ma ...
- Java并发——使用Condition线程间通信
线程间通信 线程之间除了同步互斥,还要考虑通信.在Java5之前我们的通信方式为:wait 和 notify.Condition的优势是支持多路等待,即可以定义多个Condition,每个condit ...
- Topself
TopShelf简介 个人理解:开源.跨平台的服务框架.提供一种方式以控制台编写windows服务,与windows服务相比,目前只发现便于调试. 官网网站:http://docs.topshelf- ...
- PHP中刷新输出缓冲
http://www.cnblogs.com/mutuan/archive/2012/03/18/2404957.html PHP中刷新输出缓冲buffer是一个内存地址空间,Linux系统默认大小一 ...
- UIView的常见属性
UIView的常见属性: @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDyn ...
- c语言全局变量与局部变量(当变量重名时)的使用情况
在c语言中,变量有全局变量和局部变量之分,这一点和很多高级语言类似,如c#,java等.不过与c#,java中的局部变量如在全局变量作用域内则不允许与全局变量名相同,而c语言是允许这样做的.这样的做法 ...
- WPF动画之关键帧动画(2)
XAML代码: <Window x:Class="关键帧动画.MainWindow" xmlns="http://schemas.microsoft.com/win ...
- java新手笔记13 继承
1.Person类 package com.yfs.javase; //可以有多个子类 public class Person { private String name;// 私有属性不能继承 pr ...