【bzoj1670】[Usaco2006 Oct]Building the Moat护城河的挖掘 求凸包
来源:互联网 发布:怎么申请软件专利 编辑:程序博客网 时间:2024/05/18 03:26
Description
为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场周围挖一条护城河。农场里一共有N(8<=N<=5,000)股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水。护城河必须能保护所有的泉水,也就是说,能包围所有的泉水。泉水一定在护城河的内部,或者恰好在河道上。当然,护城河构成一个封闭的环。 挖护城河是一项昂贵的工程,于是,节约的FJ希望护城河的总长度尽量小。请你写个程序计算一下,在满足需求的条件下,护城河的总长最小是多少。 所有泉水的坐标都在范围为(1..10,000,000,1..10,000,000)的整点上,一股泉水对应着一个唯一确定的坐标。并且,任意三股泉水都不在一条直线上。 以下是一幅包含20股泉水的地图,泉水用”*”表示
图中的直线,为护城河的最优挖掘方案,即能围住所有泉水的最短路线。 路线从左上角起,经过泉水的坐标依次是:(18,0),(6,-6),(0,-5),(-3,-3),(-17,0),(-7,7),(0,4),(3,3)。绕行一周的路径总长为70.8700576850888(…)。答案只需要保留两位小数,于是输出是70.87。
Input
- 第1行: 一个整数,N * 第2..N+1行: 每行包含2个用空格隔开的整数,x[i]和y[i],即第i股泉水的位 置坐标
Output
- 第1行: 输出一个数字,表示满足条件的护城河的最短长度。保留两位小数
Sample Input
202 103 722 1512 1120 328 91 129 314 1425 68 125 128 424 124 1513 526 521 1124 41 8
Sample Output
70.87
HINT
Source
凸包 卡壳
裸题…
原谅我这么晚学凸包…
模板挺好写的…
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>using namespace std;typedef long long LL;const int SZ = 1000010;const int INF = 1000000010;const double eps = 1e-6;struct point{ double x,y;}p[SZ],S[SZ];double pw2(double x){ return x * x;}point operator -(const point &a,const point &b){ return (point){a.x - b.x,a.y - b.y};}double operator *(const point &a,const point &b){ return a.x * b.y - a.y * b.x;}double dist(const point &a,const point &b){ return sqrt(pw2(a.x - b.x) + pw2(a.y - b.y));}bool cmp(const point &a,const point &b){ double t = (a - p[1]) * (b - p[1]); if(fabs(t) < eps) return dist(a,p[1]) < dist(b,p[1]); return t < 0;}int n;double graham(){ int k = 1; for(int i = 2;i <= n;i ++) if(p[i].x < p[k].x || (p[i].x == p[k].x && p[i].y < p[k].y)) k = i; swap(p[1],p[k]); sort(p + 2,p + 1 + n,cmp); int top = 0; S[++ top] = p[1]; S[++ top] = p[2]; for(int i = 3;i <= n;i ++) { while(top > 1 && (p[i] - S[top - 1]) * (S[top] - S[top - 1]) < 0) top --; S[++ top] = p[i]; } double ans = 0; for(int i = 1;i <= top;i ++) ans += dist(S[i],S[i == top ? 1 : i + 1]); return ans;}int main(){ scanf("%d",&n); for(int i = 1;i <= n;i ++) scanf("%lf%lf",&p[i].x,&p[i].y); printf("%.2lf",graham()); return 0;}
0 0
- 【bzoj1670】[Usaco2006 Oct]Building the Moat护城河的挖掘 求凸包
- bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘
- bzoj1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 计算几何 凸包
- 【bzoj1670】[Usaco2006 Oct]Building the Moat护城河的挖掘 凸包
- [BZOJ1670][Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
- bzoj1670[Usaco2006 Oct]Building the Moat护城河的挖掘 凸包(Andrew)
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- BZOJ 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
- [Usaco2006 Oct] Building the Moat护城河的挖掘
- BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘|二维凸包
- 【BZOJ 1670】[Usaco2006 Oct]Building the Moat护城河的挖掘 裸凸包
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包)
- BZOJ 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘 凸包
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
- [凸包]BZOJ 1670——[Usaco2006 Oct]Building the Moat护城河的挖掘
- ppt背景
- POJ 1789
- Sql Server 使用脚本对表的列进行操作
- php 数组操作
- 课堂作业9
- 【bzoj1670】[Usaco2006 Oct]Building the Moat护城河的挖掘 求凸包
- Struts2学习笔记(Tags)
- QtQuick获取屏幕信息
- 如何成功制作可执行的Jar包
- hdoj 1872 稳定排序 【判断排序是否稳定】
- 实现performSelector 传递多个参数
- Scrapy+splash抓取js生成的数据
- android 自定义组件中常用的方法
- iOS: 如何在工程中设置 DEBUG 模式?