Wall(凸包)
http://poj.org/problem?id=1113
题意:给出一些点的坐标,和一个半径r,求出这些点围成的凸包的周长再加上一个半径为r的圆的周长。
#include <stdio.h>
#include <algorithm>
#include <math.h>
const double PI=acos(-1.0);
const int N=;
using namespace std; struct Point
{
double x;
double y;
Point (double x = ,double y = ):x(x),y(y) {}
bool friend operator < (const Point &a, const Point &b)
{
return a.x < b.x||(a.x==b.x&&a.y < b.y);
}
} p[N],c[N];
typedef Point Vector;
double dis(Point A,Point B)//两点间的距离
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
Vector operator- (Point A,Point B)//求向量
{
return Vector(B.x-A.x,B.y-A.y);
}
double Cross(Vector A,Vector B)//求叉积
{
return A.x*B.y-A.y*B.x;
}
int ConvexHull(Point *p,int n,Point *c)//计算凸包
{
int k = ;
for (int i = ; i < n; i++)
{
while(k > && Cross(c[k-]-c[k-],c[k-]-p[i])<=)
k--;
c[k++] = p[i]; }
int m = k;
for (int i = n-; i >= ; i--)
{
while(k > m && Cross(c[k-]-c[k-],c[k-]-p[i])<=)
k--;
c[k++] = p[i];
}
c[k] = c[];
return k;
} int main()
{
int n;
double r;
scanf("%d %lf",&n,&r);
for (int i = ; i < n; i++)
scanf("%lf %lf",&p[i].x,&p[i].y);
sort(p,p+n);
int cnt = ConvexHull(p,n,c);
double len = ;
for (int i = ; i <= cnt; i++)
{
len+=dis(c[i],c[i-]);
}
len+=*PI*r;
printf("%.0f",len);
return ;
}
Wall(凸包)的更多相关文章
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- POJ1113 Wall —— 凸包
题目链接:https://vjudge.net/problem/POJ-1113 Wall Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- 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 (凸包算法学习)
题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...
- POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...
- Wall(凸包POJ 1113)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32360 Accepted: 10969 Description On ...
- POJ1113 Wall 凸包
题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...
- HDU1348 Wall 凸包
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1348 题意:给出一个凸包,求出与凸包距离 L的外圈周长 凸包模板题,练练Andrew算法求出凸包周长再 ...
- POJ 1113 Wall 凸包 裸
LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...
随机推荐
- inflate(int resource, ViewGroup root, boolean attachToRoot)见解
/** * Inflate a new view hierarchy from the specified xml resource. Throws * {@link InflateException ...
- MVC Ajax调用Action时-OnActionExecuting RedirectResult 无法跳转的处理办法
public class BaseController : Controller { protected override void OnActionExecuting(ActionExecuting ...
- python学习笔记--关于函数的那点事1
函数参数 1.位置参数 类似于java函数的基本参数,按照顺序和结构定义参数 2.默认参数 def method(param,defaultParam=defaultValue) 调用时,可以调用me ...
- kvm virt-install 使用小结
简介: virt-install 能够为KVM.Xen或其它支持libvrit API的hypervisor创建虚拟机并完成GuestOS安装. 此外,它能够基于串行控制台.VNC或SDL支持文本或图 ...
- Day10 图形用户界面和游戏开发
基于tkinter模块的GUI GUI是图形用户界面的缩写,图形化的用户界面对使用过计算机的人来说应该都不陌生,在此也无需进行赘述.Python默认的GUI开发模块是tkinter(在Python 3 ...
- 让TP5.0在SWOOLE上飞起来
TP-SWOOLE 目前,TP5.1官方已经提供了think-swoole2.0,集成程度以前优雅很多,不过5.0的集成方式确实有些鸡肋.所以看了下2.0,为5.0开发了一个扩展包,可以采用compo ...
- 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 1
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
- (39.4) Spring Boot Shiro权限管理【从零开始学Spring Boot】
在读此文章之前您还可能需要先了解: (39.1) Spring Boot Shiro权限管理[从零开始学Spring Boot] http://412887952-qq-com.iteye.com/b ...
- ReatEasy+用户指南----第9章@MatrixParam
转载说明出处:http://blog.csdn.net/nndtdx/article/details/6870391 原文地址 http://docs.jboss.org/resteasy/docs/ ...
- RestEasy+用户指南----第5章.@PathParam
转载说明出处:http://blog.csdn.net/nndtdx/article/details/6870391 原文地址 http://docs.jboss.org/resteasy/docs/ ...