bzoj 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘——凸包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670
用叉积判断。注意两端的平行于 y 轴的。
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define ll long long #define db double using namespace std; const int N=5005,INF=1e7; int n,sta[N],top;db ans; struct Node{int x,y;Node(int x=0,int y=0):x(x),y(y) {}bool operator< (const Node &b)const{return x<b.x||(x==b.x&&y<b.y);}Node operator- (const Node &b)const{return Node(b.x-x,b.y-y);} }a[N]; ll Sqr(int x){return (ll)x*x;} ll Cross(Node a,Node b){return (ll)a.x*b.y-(ll)a.y*b.x;} db dist(Node a,Node b){return sqrt(Sqr(a.x-b.x)+Sqr(a.y-b.y));} int main() {scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);sort(a+1,a+n+1);for(int i=1;i<=n;i++){while(top>1&&Cross(a[i]-a[sta[top]],a[i]-a[sta[top-1]])>=0)top--;sta[++top]=i;}for(int i=2;i<=top;i++)ans+=dist(a[sta[i-1]],a[sta[i]]);for(int i=1;i<=n;i++)a[i].y=INF-a[i].y+1;sort(a+1,a+n+1);top=0;for(int i=1;i<=n;i++){while(top>1&&Cross(a[i]-a[sta[top]],a[i]-a[sta[top-1]])>=0)top--;sta[++top]=i;}for(int i=2;i<top;i++)ans+=dist(a[sta[i-1]],a[sta[i]]);if(top>1&&a[sta[top]].x!=a[sta[top-1]].x)ans+=dist(a[sta[top-1]],a[sta[top]]);if(a[1].x==a[2].x)ans+=abs(a[1].y-a[2].y);printf("%.2f\n",ans);return 0; }
转载于:https://www.cnblogs.com/Narh/p/10143271.html
bzoj 1670 [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 ...
- bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 387 Sol ...
- 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 ...
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...
- bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛*
bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛 题意: 求最长单调递增子序列,序列大小≤5000 题解: 蒟蒻弱写了一个O(n^2)的. 代码: 1 #include ...
- BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)
BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec Memory Limit: 64 MB Description 正如你所知 ...
最新文章
- TIOBE 1月编程语言排行榜:C语言再度「C 位」出道,Python惜败
- 元素垂直水平居中布局
- Java好不好学?有哪些入门技巧?
- CSDN 首页的第一屏 广告/新闻 比率 = 40 : 2
- 收藏列表放入MySQL还是redis_mysql导入redis
- 【操作系统】实验 生产者-消费者问题解决方案
- np.cross函数详解
- 经常读书与不读书的人有什么区别?
- html传值 location.search取
- 清华大学 c语言 大作业,雷课堂(THUnderClass)——清华大学2020C++大作业个人项目记录与总结...
- html中描文本链接,锚文本、超链接和纯文本链接的区别以及使用方法
- 【强大的数字设计工具包】Sketch 55.1 for Mac
- PTA数据结构-01-复杂度1 最大子列和问题
- .net 开发工程师 面试题
- iphone计算机照片要求,如何将照片从iPhone传输到计算机
- 巧妙利用回收站做文件隐藏
- python爬取微博恶评_详解用python写网络爬虫-爬取新浪微博评论
- 我从实习到现在的经历,幸运女神总会来到!
- Android q索尼手机相机算法,手机厂商套路太多!竟在手机摄像头上玩“掩眼法”?...
- 使用calibre制作带目录的mobi电子书
热门文章
- 发现在创建云服务器ecs实例的磁盘快照时_【New Feature】阿里云快照服务技术解析...
- mysql循环队列_数据结构:循环队列
- Node.js 路由的简单使用
- Vue.JS项目输入框中使用v-model导致number类型值自动转换成string问题的解决方案
- Mac终端的ruby和pods安装和使用(超干货)
- JS以及CSS对页面的阻塞
- cas实现单点登录原理
- 收购Roambi,SAP欲领导商务分析云迁移全球市场
- 从 Hello World 开始
- 几种流行Webservice控制框架