转自: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. ubuntu中写一个shell脚本的过程

    gedit hello.sh ,然后输入 #!/bin/bash echo "Hello world!" chmod +x hello.sh ./hello.sh

  2. 线程基础:JDK1.5+(8)——线程新特性(上)

    1.概要 假设您阅读JAVA的源码.出现最多的代码作者包含:Doug Lea.Mark Reinhold.Josh Bloch.Arthur van Hoff.Neal Gafter.Pavani D ...

  3. [iOS翻译]《iOS7 by Tutorials》在Xcode 5里使用单元測试(上)

    简单介绍: 单元測试是软件开发的一个重要方面.毕竟,单元測试能够帮你找到bug和崩溃原因,而程序崩溃是Apple在审查时拒绝app上架的首要原因. 单元測试不是万能的,但Apple把它作为开发工具包的 ...

  4. DNS隧道工具汇总——补充,还有IP over DNS的工具NSTX、Iodine、DNSCat

    github上有一堆的工具:https://github.com/search?utf8=%E2%9C%93&q=DNS+tunnel+&type= DNS隧道大检阅 研究了一天的DN ...

  5. Noip前紧急抢救

    管他会不会,知道结论就好了 紧急抢救知识 斯特林数 第一类斯特林数 递推公式 \[ S[n][k]=(n-1)\times S[n-1][k]+S[n-1][k-1] \] 处理的问题是将n个数划分为 ...

  6. Api接口服务的设计和安全解决方案

    这个涉及到两个方面问题:一个是接口访问认证问题,主要解决谁可以使用接口(用户登录验证.来路验证)一个是数据数据传输安全,主要解决接口数据被监听(HTTPS安全传输.敏感内容加密.数字签名) 普通网站应 ...

  7. 洛谷P4016 负载平衡问题(最小费用最大流)

    题目描述 GG 公司有 nn 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 nn 个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运. 输入输出格式 输入格 ...

  8. <错误>

    1. package com.multak.cookaraclient.adapter; import android.content.Context; import android.support. ...

  9. python爬虫:爬取医药数据库drugbank

    这个是帮朋友做的,难点就是他们有一个反爬虫机制,用request一直不行,后面我就用selenium直接把网页copy下来,然后再来解析本地的html文件,就木有问题啦. 现在看来,写得有点傻,多包涵 ...

  10. How an Event Enters a Cocoa Application

    How an Event Enters a Cocoa Application An event is a low-level record of a user action that is usua ...