POJ1113 Wall 凸包
题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度。
题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题。
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 100005
#define PI acos(-1)
using namespace std; struct node
{
int x,y;
}point[MAX]; int Stuck[MAX],n,l,top; bool cmp(struct node A,struct node B)
{
if(A.y < B.y)
return true;
if(A.y==B.y && A.x<B.x)
return true;
return false;
} int Cross(int x1,int y1,int x2,int y2,int x3,int y3)
{
return (x1-x2)*(y1-y3)-(x1-x3)*(y1-y2);
} void Graham()
{
memset(Stuck,,sizeof(Stuck));
Stuck[]=;
Stuck[]=;
top=;
for(int i=;i<n;i++)
{
while(top> && Cross(point[Stuck[top]].x,point[Stuck[top]].y,point[Stuck[top-]].x,point[Stuck[top-]].y,point[i].x,point[i].y)<=)
top--;
Stuck[++top]=i;
}
int len=top;
Stuck[++top]=n-;
for(int i=n-;i>=;i--)
{
while(top!=len && Cross(point[Stuck[top]].x,point[Stuck[top]].y,point[Stuck[top-]].x,point[Stuck[top-]].y,point[i].x,point[i].y)<=)
top--;
Stuck[++top]=i;
}
} double Dist(int pos1,int pos2)
{
return sqrt((point[pos1].x-point[pos2].x)*(point[pos1].x-point[pos2].x)*1.0+(point[pos1].y-point[pos2].y)*(point[pos1].y-point[pos2].y));
} int main()
{
int k;
while(scanf("%d%d",&n,&l)!=EOF)
{
k=;
for(int i=;i<n;i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
if(point[k].y > point[i].y || (point[k].x>point[i].x && point[k].y==point[i].y))
k=i;
}
swap(point[],point[k]);
sort(point+,point+n,cmp);
Graham();
double sum=;
sum+=Dist(Stuck[],Stuck[top])+*PI*l;
for(int i=;i<=top;i++)
sum+=Dist(Stuck[i],Stuck[i-]);
int ans=(int)(sum+0.5);
printf("%d\n",ans);
}
return ;
}
POJ1113 Wall 凸包的更多相关文章
- POJ1113 Wall —— 凸包
题目链接:https://vjudge.net/problem/POJ-1113 Wall Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ1113:Wall (凸包算法学习)
题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...
- POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the ...
- POJ1113 Wall
题目来源:http://poj.org/problem?id=1113题目大意: 如图所示,给定N个顶点构成的一个多边形和一个距离值L.建立一个围墙,把这个多边形完全包含在内,且围墙距离多边形任一点的 ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- POJ-1113 Wall 计算几何 求凸包
题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...
- POJ1113 Wall【凸包】
题意: 求把城堡围起来需要的最小墙壁周长. 思路: 围墙周长为=n条平行于凸包的线段+n条圆弧的长度=凸包周长+围墙离城堡距离L为半径的圆周长. 代码: ...还是看大佬写的,自己做个记录方便日后复习 ...
- POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
随机推荐
- 从excel读数据到informix的Found a quote for which there is no matching quote错误
我从excel读取数据,然后存储到Informix数据库里.偶尔会发现出现Found a quote for which there is no matching quote这个错误.调试后发现,是因 ...
- C# 语言规范_版本5.0 (第14章 枚举)
1. 枚举 枚举类型 (enum type) 是一种独特的值类型(第 4.1 节),它用于声明一组命名的常量. 下面的示例 enum Color { Red, Green, Blue } 声明一个名为 ...
- Table表格横竖线实现Css
.tablel { border-collapse:collapse; /* 关键属性:合并表格内外边框(其实表格边框有2px,外面1px,里面还有1px哦) */ border:solid #999 ...
- 关于C语言知识调查
因为上一篇随笔对这一部分写得不够清楚,因此在这篇做一些补充. 你是怎么学习C语言的? 起初,对于C语言的学习主要是通过老师课堂的教学,完成相关的课后作业.与我的技能相比的话,他们都有一个共同点需要去实 ...
- UIBezierPath与CAShapeLayer结合画扇形
/*让半径等于期望半径的一半 lineWidth等于期望半径 就可以画圆*/ 可以看出layer的走势是从圆边的中间一半在圆外 一半在圆内 因此让半径等于期望半径的一半 lineWidth等于期望半径 ...
- 转:apache 的mod-status
最近发现在apache的监控方面,apache 2开始自带的apache mod-status其实是个不错的工具,下面摘录并笔记之: 如果是linux的话,可以这样设置: 在httpd.conf中添加 ...
- 未知的生成错误 因为没有预加载,所以无法解析程序集 GalaSoft.MvvmLight
使用wpf开发时,在ViewModel中引用了DevExpress注册的GalaSoft.MvvmLight命名空间,使用其ViewModelBase,在View界面中绑定事件时出现错误: 错误 13 ...
- 第四节,Linux基础命令
第四节,Linux基础命令 命令是系统操作员对系统传入的指令,传入指令后回车,系统接收到指令做出相应的行为 1.查看用户位于系统什么位置 [pmd]检查操作用户位于系统的什么位置 命令 ...
- JavaScript的内置对象(Date日期+string字符串)基础语法总结
1.Date日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 1)定义一个时间对象 : var Udate=new Date(); //注意:使用关键字new,Date()的首 ...
- 【LeetCode】463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...