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 ...
随机推荐
- Loadrunner得到server參数
首先你得确定你所监视的server与你的測试机是在同一个局域网内, 监控windows系统: 1.监视连接前的准备工作 1)进入被监视windows系统.开启下面二个服务Remote ...
- ios Button
展现效果例如以下: 功能说明: 1加入来图片背景, 2动态展现百度网页, 3动态加入button. 4展现提示框.展现你点击提示框得index 我成功来你也快来试试. 1 详细得项目创建与拖动but ...
- Hbase集群扩展
当hbase集群节点不够用时,我们须要新增节点来对集群进行扩展.hbase集群的扩展是非常easy的,过程例如以下: 一.准备一台新机器作为扩展节点,这里是作为slaves15,该机子要先与maste ...
- iOS_第3方类库MBprogressHUD
1,将下载好的第3方类库MBprogressHUD源代码包增加到project(事实上就是一个.h和.m文件) 2,进入project的Build Phases,将源代码包里面的所有.m文件所有加入到 ...
- Spark SQL with Hive
前一篇文章是Spark SQL的入门篇Spark SQL初探,介绍了一些基础知识和API,可是离我们的日常使用还似乎差了一步之遥. 终结Shark的利用有2个: 1.和Spark程序的集成有诸多限制 ...
- c语言实现皇帝翻牌游戏
一个综合的游戏,对所学的知识进行整合!融会贯通! #include <stdio.h> #include <stdlib.h> #include <string.h> ...
- Swift 实践之UIWebView
1.选中工程,点击右键,New File>在iOS下选中Othe>Empty,生成一个.js的脚本文件,将代码粘贴过去保存; var script = document.createEle ...
- Java-MyBatis: MyBatis3 | Java API
ylbtech-Java-MyBatis: MyBatis3 | Java API 1.返回顶部 1. Java API 既然你已经知道如何配置 MyBatis 和创建映射文件,你就已经准备好来提升 ...
- 给centos重新安装yum的base-repo源
转自:https://blog.csdn.net/lovemysea/article/details/79552952 如果自己的centos的系统yum源出现问题了,如何才能修复? 方式一:使用国内 ...
- linux下服务启动脚本
#!/usr/bin/env python# -*- coding: utf-8 -*-# @File : deployment.py# @Author: Anthony.waa# @Date : 2 ...