USACO 5.1.1凸包
转自:http://blog.csdn.net/cnyali/article/details/50097593
程序:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std; typedef struct
{
double x,y;
}P;
typedef struct
{
int s,t;
double k,l;
}E; int n,top;
double sum;
P p[10010];
E e[20020]; bool comp(const P &a,const P &b)
{
return a.x<b.x;
} double dist(int a,int b)
{
return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
} double slope(int a,int b)
{
if (p[b].x-p[a].x==0) return 0;
return (p[b].y-p[a].y)*1.0/(p[b].x-p[a].x);
} int main()
{
freopen("fc.in","r",stdin);
freopen("fc.out","w",stdout);
int i,j;
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort (p+1,p+n+1,comp);
i=1;
while (i<n) {
j=i+1;
e[++top].s=i;
e[top].t=j;
e[top].l=dist(i,j);
e[top].k=slope(i,j);
while (top>1&&e[top-1].k>e[top].k) {
top--;
e[top].t=e[top+1].t;
e[top].l=dist(e[top].s,e[top].t);
e[top].k=slope(e[top].s,e[top].t);
}
i++;
}
while (top>0) sum+=e[top--].l;
i=1;
while (i<n) {
j=i+1;
e[++top].s=i;
e[top].t=j;
e[top].l=dist(i,j);
e[top].k=slope(i,j);
while (top>1&&e[top-1].k<e[top].k) {
top--;
e[top].t=e[top+1].t;
e[top].l=dist(e[top].s,e[top].t);
e[top].k=slope(e[top].s,e[top].t);
}
i++;
}
while (top>0) sum+=e[top--].l;
printf("%.2f\n",sum);
return 0;
}
USACO 5.1.1凸包的更多相关文章
- 【COGS & USACO】896. 圈奶牛(凸包)
http://cojs.tk/cogs/problem/problem.php?pid=896 我的计算几何入门题... 看了看白书的计算几何部分,,恩好嘛.. 乃们都用向量!!!! 干嘛非要将2个点 ...
- USACO Section 5.1 Fencing the Cows(凸包)
裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...
- USACO JAN14 奶牛冰壶运动 凸包+判定
满足条件的一定是在凸包内的,直接判断 恬不知耻的加了特判,2333 #include<cstdio> #include<iostream> #include<cstrin ...
- 【COGS】714. USACO 1.3.2混合牛奶(贪心+水题)
http://cojs.tk/cogs/problem/problem.php?pid=714 在hzwer的刷题记录上,默默地先跳过2题T_T...求凸包和期望的..T_T那是个啥..得好好学习 看 ...
- usaco silver
大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草 裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...
- LG2742 【模板】二维凸包 / [USACO5.1]圈奶牛Fencing the Cows
题意 题目描述 农夫约翰想要建造一个围栏用来围住他的奶牛,可是他资金匮乏.他建造的围栏必须包括他的奶牛喜欢吃草的所有地点.对于给出的这些地点的坐标,计算最短的能够围住这些点的围栏的长度. 输入输出格式 ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
随机推荐
- 一点一点学架构(四)—Spring.NET错误Cannot Resolve Type……
背景 在搭建完项目框架之后,当我利用单元測试来測一条线时.出现了下面错误: Cannot resolve type[--]for object with name 'ButtonBll' define ...
- 路由器wiff设置
1.将一根网线连接至路由wankou 2.将另外一根网页连接1.2.3.4口中一个,另外一个连接至电脑 3.登录192.168.1.1,进行设置向导选择ppoe,然后登录网络设置无线名称+密码 4.保 ...
- Object::connect: Cannot queue arguments of type 'QMap<QString,QString>'(要使用qRegisterMetaType<StringMap>进行注册)
QObject::connect: Cannot queue arguments of type 'QMap<QString,QString>',(Make sure 'QMap<Q ...
- 0x08 总结与练习
1:前面已经搞好了. 2:poj2965 这种开关问题一个点要么点一次要么不点,枚举所有点的方案实行即可 #include<cstdio> #include<iostream> ...
- NEUOJ 1702 撩妹全靠魅力值 (三维偏序)
题目链接:http://acm.neu.edu.cn/hustoj/problem.php?id=1702 题目大意:就是问每个人三个属性同时不低于另外几个人....人不分先后 经典的三维偏序问题 解 ...
- QEMU/KVM磁盘在线备份
QEMU/KVM磁盘的在线完整及增量备份,是"打包"方案的一种具体实现,可实现基于时间点的备份,同时支持本地与远程2种备份方式,并可指定备份文件进行恢复. tag: qemu, k ...
- jqury中$("#div").index($this)在setTimeoutt中返回值一直是-1的问题解决方案
今天遇到一个十分蛋疼的问题,花了我一个多小时才解决,其实十分简单,但我是新手,好了,事情是这样的: 我想让鼠标停留在某个元素一定时间再显示它隐藏的内容(不然你鼠标快速滑上滑下,反反复复,如果碰上sli ...
- 用endnote导入bib
首先一般时候需要把IEEE的style包导入. https://endnote.com/downloads/styles/ 具体方法可参考http://muchong.com/html/201006/ ...
- Ubuntu包管理工具整理
概述 常用的包管理包含三类工具:dpkg.apt和aptitude.1 dpkg 主要是对本地的软件包进行管理,本地软件包包括已经在本地安装的软件包和已经下载但还没有安装的 deb 文件,不解决依赖关 ...
- Type system
Type system[edit] Main articles: Data type, Type system, and Type safety A type system defines how a ...