转自: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. chmod和chown命令具体使用方法

    Linux下数字表示文件的操作权限(777,755,..) Linux下.查看某路径下用(ls -l)查看全部文件的具体属性列表时.会看到文件的操作权限.类似"drwxr-xr-x" ...

  2. C++ 嵌入汇编程序提高计算效率

    因为汇编语言比C++更接近硬件底层,所以在性能要求高的程序中往往能够採取在C++代码中嵌入汇编的方式来给程序提速. 在VC中能够简单的通过 __asm { //在这里加入汇编代码 } 来实现. 以下通 ...

  3. iOS开发实践之网络检測Reachability

    在网络应用开发中.有时须要对用户设备的网络状态进行实时监控.以至于对用户进行友好提示 或者依据不同网络状态处理不一样的逻辑(如视频播放app,依据当前的网络情况自己主动切换视频清晰度等等).用Reac ...

  4. 通过meta标签改变浏览器内核做兼容

    <meta name="renderer" content="webkit|ie-stand|ie-comp" /> <meta http-e ...

  5. Codeforces 558B Amr and The Large Array

    B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input st ...

  6. 多线程编程TSL相关的技术文档

    线程本地存储 (TLS) https://msdn.microsoft.com/zh-cn/library/6yh4a9k1(v=vs.80).aspx Using Thread Local Stor ...

  7. tensorflow利用预训练模型进行目标检测(一):安装tensorflow detection api

    一.tensorflow安装 首先系统中已经安装了两个版本的tensorflow,一个是通过keras安装的, 一个是按照官网教程https://www.tensorflow.org/install/ ...

  8. Oracle数据库中闪回恢复的详细分析

    Oracle9i开始提供闪回查询,以便能在需要的时候查到过去某个时刻的一致性数据,这是通过Undo实现的.这个功能有很大的限制,就是相关事务的undo不能被覆盖,否则就无力回天了.oracle10g大 ...

  9. IPython Autoreload

    在PyCharm中进行代码调试的时候, 设置修改的模块自动重新载入是非常方便的 In [1]: %load_ext autoreload In [2]: %autoreload 2

  10. Flask-Restful

    定义Restful的视图 安装:pip install flask-restful 如果使用Flask-restful,那么定义视图函数的时候,就要继承flask_restful.Resourse类, ...