bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
Time Limit: 3 Sec Memory Limit: 64 MB id=1670" style="color:blue; text-decoration:none">Discuss
Submit: 387 Solved: 288
[Submit][Status][
Description
为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场周围挖一条护城河。
农场里一共同拥有N(8<=N<=5,000)股泉水,而且,护城河总是笔直地连接在河道上的相邻的两股泉水。护城河必须能保护全部的泉水,也就是说,能包围全部的泉水。泉水一定在护城河的内部,或者恰好在河道上。当然。护城河构成一个封闭的环。
挖护城河是一项昂贵的project,于是,节约的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
2 10
3 7
22 15
12 11
20 3
28 9
1 12
9 3
14 14
25 6
8 1
25 1
28 4
24 12
4 15
13 5
26 5
21 11
24 4
1 8
Sample Output
HINT
Source
凸包模板题
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define maxn 5005
using namespace std;
int n,top;
double ans;
struct P{int x,y;}p[maxn],s[maxn];
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline P operator-(const P &a,const P &b)
{
return (P){a.x-b.x,a.y-b.y};
}
inline ll operator*(const P &a,const P &b)
{
return a.x*b.y-a.y*b.x;
}
inline ll dis(P a,P b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline bool operator<(const P &a,const P &b)
{
ll t=(a-p[1])*(b-p[1]);
if (t==0) return dis(p[1],a)<dis(p[1],b);
else return t<0;
}
inline void solve()
{
int t=1;
F(i,2,n) if (p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x)) t=i;
swap(p[1],p[t]);
sort(p+2,p+n+1);
s[++top]=p[1];s[++top]=p[2];
F(i,3,n)
{
while (top>=2&&(s[top]-s[top-1])*(p[i]-s[top-1])>=0) top--;
s[++top]=p[i];
}
s[top+1]=p[1];
F(i,1,top) ans+=sqrt(dis(s[i],s[i+1]));
}
int main()
{
n=read();
F(i,1,n) p[i].x=read(),p[i].y=read();
solve();
printf("%.2lf\n",ans);
return 0;
}
bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘的更多相关文章
- BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
裸的凸包...(和旋转卡壳有什么关系吗...蒟蒻求教T T) 话说忘了怎么写了...(我以前都是先做上凸壳再做下凸壳的说) 于是看了下hzwer的写法,用了向量的点积,方便多了,于是果断学习(Orz) ...
- 【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 -- 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Description 为了防止 ...
- BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包
BZOJ_1670_[Usaco2006 Oct]Building the Moat护城河的挖掘_求凸包 Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场 ...
- 【BZOJ】1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1670 裸打了凸包.. #include <cstdio> #include <cs ...
- 牛客假日团队赛5J 护城河 bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包的周长)
链接:https://ac.nowcoder.com/acm/contest/984/J 来源:牛客网 护城河 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
Description 求凸包周长. Sol 凸包+计算几何. 这好像叫什么 Graham Scan 算法... 这个可以求凸包的周长,直径,面积. 选择一个基点,然后按极角排序,最后用一个栈一直维护 ...
- bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘【凸包】
凸包模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> ...
- [bzoj1670][Usaco2006 Oct]Building the Moat
Description 为了防止口渴的食蚁兽进入他的农场,$Farmer John$决定在他的农场周围挖一条护城河.农场里一共有$N$股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水.护城河 ...
随机推荐
- [BZOJ3205][APIO2013]Robot(斯坦纳树)
3205: [Apio2013]机器人 Time Limit: 15 Sec Memory Limit: 128 MBSubmit: 1007 Solved: 240[Submit][Status ...
- 【数论】【快速幂】bzoj1008 [HNOI2008]越狱
根据 高中的数学知识 即可推出 ans=m^n-m*(m-1)^(n-1) .快速幂取模搞一下即可. #include<cstdio> using namespace std; typed ...
- Java多线程——ReentrantReadWriteLock源码阅读
之前讲了<AQS源码阅读>和<ReentrantLock源码阅读>,本次将延续阅读下ReentrantReadWriteLock,建议没看过之前两篇文章的,先大概了解下,有些内 ...
- IOS,苹果内购和添加广告
内购——应用内购买 通过苹果应用程序商店有三种主要赚钱的方式: 直接收费(与国内大部分用户的消费习惯相悖) 广告(降低用户体验 应用程序名称带Lite可以添加广告) O2O -> Online推 ...
- mysql replication 复制的一些问题
1 过大的复制延迟 mysql 的复制延迟是一个常见问题,现在已经有一些解决方案,如淘宝开发的一些工具 2 没有磁盘空间 复制导致磁盘空间塞满,二进制日志.中继日志或临时文件把磁盘塞满,slave ...
- [HTML/CSS]uploadify自定义按钮样式
概述 在项目中经常用到uploadify上传插件,但是FLASH按钮的外观往往跟我们网页的设计的主题色不太搭配.这时就需要对其样式进行修改. 样式文件是uploadify.css. 打开这个文件后,你 ...
- 针对标签中设置 disabled="true",$("#id").serialize()获取不到value的解决方法
今天给<select>增加disabled="true", 发现$("#form").serialize()的结果不包含select标签的值,解决办 ...
- centos系统的时间时区和MySQL的时间时区问题
原文:http://1567045.blog.51cto.com/1557045/1074971 centos系统的时间时区和MySQL的时间时区问题 年轻人做事要细心,特别我们这些搞IT的千万不莽 ...
- pdf.js 添加自定义loading动画
最近做了个手机端pdf预览的功能,用到pdf.js这个库,效果还不错.但是在网络差.文件大时,页面一直空白,体验不是很好. 于是加了个loading动画. <div id="loadi ...
- 微信php分享页面自定义标题与内容
1.因为现在分享页面,发给朋友或者朋友圈都没办法自定义标题.图片和内容,所以必须要有微信公众号 2.如果有微信公众号可直接登录,如果没有要注册,注册完或者登录了 3.查看你的权限,左侧最下面开发的接口 ...