bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
Time Limit: 3 Sec Memory Limit: 64 MB
Submit: 387 Solved: 288
[Submit][Status][Discuss]
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;
}
转载于:https://www.cnblogs.com/yangykaifa/p/7263030.html
bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘相关推荐
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 624 Sol ...
- 牛客假日团队赛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护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670 用叉积判断.注意两端的平行于 y 轴的. #include<cstdio> ...
- bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛*
bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛 题意: 求最长单调递增子序列,序列大小≤5000 题解: 蒟蒻弱写了一个O(n^2)的. 代码: 1 #include ...
- [BZOJ1669][Usaco2006 Oct]Hungry Cows饥饿的奶牛
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1000 Solved: 6 ...
- bzoj 1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛(BFS)
1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛 Time Limit: 1 Sec Memory Limit: 64 MBSec Special Judge S ...
- bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(DP)
1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 786 So ...
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 990 Solved: 64 ...
- BFS【bzoj1667】: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛
1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛 Description 经过跟Farmer John长达数年的谈判,奶牛们终于如愿以偿地得到了想要的旱冰鞋.农场上大 ...
最新文章
- 010-你觉得单元测试可行吗
- android判断耳机
- python turtle画彩虹-Python利用turtle库绘制彩虹代码示例_天津SEO
- 1 0.99999的悖论_悖论向量中文版下载_悖论向量中文版单机游戏下载
- python 傅立叶函数_python 图像的离散傅立叶变换实例
- 欢乐ssl暑假赛【2019.8.6】
- 迈入JavaWeb第一步,Java网络编程基础,TCP网络编程URL网络编程等
- java 类型推理_java 11 局部变量类型推断
- linux 网络劫持编程,Linux下实现劫持系统调用的总结(上)--代码及实现
- Java多线程学习二十七:AtomicInteger 在高并发下性能不好,如何解决?为什么?
- Mybatis3.5.4官网下载
- 可编程接口芯片8255A
- Avue表单select相关
- 为何最简单的破坏命令通过了众多杀软
- 超声光学成像突破衍射极限
- ChucK初步(9)
- redis的高级教程
- Linux:内核调试之内核魔术键sysrq
- ps 2022 保存打开文件闪退解决方法
- c语言指针一览第一部分(新手向)
热门文章
- 【 HDU - 1215 】七夕节(数论,约数和公式)
- java 自定义xml_6.1 如何在spring中自定义xml标签
- java 与 xml_xml与java对象转换
- 编码方式_【每日一题】| 常见的编码方式之栅栏密码
- 新代数控系统参数说明书_台湾新代宏程序编程书
- oracle临时表空间占用率过高,ORACLE 临时表空间使用率过高的原因及临时解决方案...
- java中如何生成随机数?
- ckeditor5自定义 vue_vue中的富文本编辑器CKEditor5
- Projection投影
- Linux加密框架crypto AES代码相关