= =回归。。【UVAlive】6859凸包
来源:互联网 发布:林黛玉 知乎 编辑:程序博客网 时间:2024/05/19 00:48
= =这道题看了题面画了画图就没想用凸包做
试了试暴力。。。然而失败了。。。
凸包
。
。
。
用了别人的模板。。。侵删
解题思路:输入数据的时候把一个点变为上下左右的四个点,然后用凸包筛一遍点,需要注意边长只能是1和根号2,因为所有点都在网格上。。
最后直接输出就行
大佬的公式:
double x=fabs(a.x-b.x); double y=fabs(a.y-b.y); return fabs(x-y)+min(x,y)*sqrt(2);
#include<iostream>#include<stdio.h>#include<math.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;struct node { double x;double y;}p[400005],s[400005];int n,m;int sq(int x){ return x*x;}double chaji(node a,node b){ return a.x*b.y-a.y*b.x;}double dist(node a,node b){ double x=fabs(a.x-b.x); double y=fabs(a.y-b.y); return fabs(x-y)+min(x,y)*sqrt(2);}node xl(node a,node b){ node c; c.x=a.x-b.x; c.y=a.y-b.y; return c;}bool cmp(node a,node b){ if(a.x==b.x) return a.y<b.y; else return a.x>b.x;}int main(){ while(scanf("%d",&n)!=EOF) { memset(s,0,sizeof(s)); double x,y;int h=0; for (int i=0;i<n;i++) { scanf("%lf%lf",&x,&y); p[h].x=x-1;p[h++].y=y; p[h].x=x+1;p[h++].y=y; p[h].x=x;p[h++].y=y+1; p[h].x=x;p[h++].y=y-1; } sort(p,p+h,cmp); int tot=0; for (int i=0;i<h;i++) { while(tot>1 && chaji(xl(s[tot-1],s[tot-2]),xl(p[i],s[tot-2]))<=0) tot--; s[tot++]=p[i]; } int k=tot; for (int i=h-2;i>=0;i--) { while(tot>k && chaji(xl(s[tot-1],s[tot-2]),xl(p[i],s[tot-2]))<=0) tot--; s[tot++]=p[i]; } if(h>1) tot--; double ans=0.0; for (int i=0;i<tot;i++) { ans+=dist(s[i],s[i+1]); } printf("%.4lf\n",ans); } return 0;}
阅读全文
0 0
- = =回归。。【UVAlive】6859凸包
- UVALive 6859--凸包
- UVALive 6859 (凸包)
- UVALive 6859 Points (凸包)
- UVALive 6859 Points (凸包)
- UVAlive 6859 Points(凸包)
- 凸包扫描 + 旋转卡壳 UVALive 4728
- UVALive 4728 (凸包 旋转卡壳)
- GREAT + SWERC = PORTO UVALive
- uvalive 6859
- UVALive 6859
- UVALive 6859
- UVALive 4986 Dome of Circus(三分、凸包、凸性函数)
- UVALive 3890 Most Distant Point from the Sea(凸包最大内接圆)
- UVALive 6859 Points
- UVALive
- UVALive
- UVALive
- 剑指offer题解C++【10】矩形覆盖
- windows2003 域用户智能卡登录配置的一些问题
- 界面上的下载导出报表的jsp模版
- 计算机编程学习之路好书推荐【转】
- JAVA建造者模式
- = =回归。。【UVAlive】6859凸包
- 系统学习 jQuery (六) 动画特效
- 修改 Github commit 的作者信息
- 多态
- 获取JQgrid 某列数据,并更换值
- 计算机系统漫游
- 1087. All Roads Lead to Rome (30) <Dijkstra优先队列>
- 存储-SDRAM
- 基于JAVA的word文件转成html