转自: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凸包的更多相关文章

  1. 【COGS & USACO】896. 圈奶牛(凸包)

    http://cojs.tk/cogs/problem/problem.php?pid=896 我的计算几何入门题... 看了看白书的计算几何部分,,恩好嘛.. 乃们都用向量!!!! 干嘛非要将2个点 ...

  2. USACO Section 5.1 Fencing the Cows(凸包)

    裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...

  3. USACO JAN14 奶牛冰壶运动 凸包+判定

    满足条件的一定是在凸包内的,直接判断 恬不知耻的加了特判,2333 #include<cstdio> #include<iostream> #include<cstrin ...

  4. 【COGS】714. USACO 1.3.2混合牛奶(贪心+水题)

    http://cojs.tk/cogs/problem/problem.php?pid=714 在hzwer的刷题记录上,默默地先跳过2题T_T...求凸包和期望的..T_T那是个啥..得好好学习 看 ...

  5. usaco silver

    大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草   裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...

  6. LG2742 【模板】二维凸包 / [USACO5.1]圈奶牛Fencing the Cows

    题意 题目描述 农夫约翰想要建造一个围栏用来围住他的奶牛,可是他资金匮乏.他建造的围栏必须包括他的奶牛喜欢吃草的所有地点.对于给出的这些地点的坐标,计算最短的能够围住这些点的围栏的长度. 输入输出格式 ...

  7. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  8. poj 2187:Beauty Contest(计算几何,求凸包,最远点对)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26180   Accepted: 8081 D ...

  9. 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 ...

随机推荐

  1. byte类型取值范围以及溢出具体解释

    例1: public class test { public static void main(String[] args) { byte a = 127 ; a = (byte)(a+3) ; Sy ...

  2. Linux 网卡驱动学习(六)(应用层、tcp 层、ip 层、设备层和驱动层作用解析)

    本文将介绍网络连接建立的过程.收发包流程,以及当中应用层.tcp层.ip层.设备层和驱动层各层发挥的作用. 1.应用层 对于使用socket进行网络连接的server端程序.我们会先调用socket函 ...

  3. PHP别名引用错误:“The use statement with non-compound name … has no effect”

    别名概述 PHP5.3+支持命名空间:namespace,命名空间的一个重要功能是能够使用别名(alias)来引用一个符合规则的名字. 命名空间支持3中形式的别名引用(或称之为引入)方式:类(clas ...

  4. 2015.04.15,外语,读书笔记-《Word Power Made Easy》 10 “如何讨论交谈习惯” SESSION 27

    继续学习交谈习惯的单词,本大章节完成. 1. front and back - and uncles ventriloquist,从belly发声(venter, venris + loquor). ...

  5. Android 利用TimerTask实现ImageView图片播放效果

    在项目开发中,往往 要用到图片播放的效果.今天就用TimerTask和ImageView是实现简单的图片播放效果. 当中,TimerTask和Timer结合一起使用.主要是利用TimerTask的迭代 ...

  6. ES等待任务——是master节点上的task任务

    等待中的任务编辑 有一些任务只能由主节点去处理,比如创建一个新的 索引或者在集群中移动分片.由于一个集群中只能有一个主节点,所以只有这一节点可以处理集群级别的元数据变动.在 99.9999% 的时间里 ...

  7. angular 兼容ie11 ie11兼容

    兼容一(new Date()用法) new Date('2018-01-01 00:00:00').getHours(); new Date('2018-01-01 00:00:00').getMin ...

  8. python中数字的排序

    lst = [2,22,4,7,18]for j in range(len(lst)): #记录内部排序的次数 i = 0 while i < len(lst)-1: if lst[i] > ...

  9. Git 学习笔记(一)

    某大牛曾经说过,版本控制的最大好处就是让你可以永远后悔,而 Git 无疑是众多版本控制软件当中的佼佼者,在开源社区更是备受青睐,那么它为何会诞生,和其他的版本控制软件项目又有什么不同?且让我们慢慢来看 ...

  10. 基于 Web 的 Go 语言 IDE - Wide 1.3.0 发布!

    http://symphony.b3log.org/article/1437292757551 欢迎各位提意见.建议,参与到 Wide 开源项目中 :-)