Wall - POJ 1113(求凸包)
题目大意:给N个点,然后要修建一个围墙把所有的点都包裹起来,但是要求围墙距离所有的点的最小距离是L,求出来围墙的长度。
分析:如果没有最小距离这个条件那么很容易看出来是一个凸包,然后在加上一个最小距离L,那么就是在凸包外延伸长度为L,如下图,很明显可以看出来多出来的长度就是半径为L的圆的周长,所以总长度就是凸包的周长+半径为L的圆的周长。

代码如下:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<string>
#include<vector>
#include<math.h>
using namespace std; const double EPS = 1e-10;
const double PI = acos(-1);
const int MAXN = 1e3+7;
int sta[MAXN], top;
int Sign(double t)
{
if(t > EPS)return 1;
if(fabs(t) < EPS)return 0;
return -1;
}
struct point
{
double x, y;
point(double x=0, double y=0):x(x), y(y){}
point operator - (const point &t)const{
return point(x-t.x, y-t.y);
}
double operator ^(const point &t)const{
return x*t.y - y*t.x;
}
double operator *(const point &t)const{
return x*t.x + y*t.y;
}
}p[MAXN];
double Dist(point a, point b)
{
return sqrt((a-b)*(a-b));
}
bool cmp(point a, point b)
{
int t = Sign((a-p[0])^(b-p[0])); if(t == 0)
return Dist(a, p[0]) < Dist(b, p[0]);
return t > 0;
}
///求凸包
void Graham(int N)
{///注意是否有1和2的情况,这个题目要求的
sta[0]=0, sta[1]=1, top=1; for(int i=2; i<N; i++)
{
while(top>0 && Sign((p[i]-p[sta[top]])^(p[sta[top-1]]-p[sta[top]])) <= 0)
top--;
sta[++top] = i;
}
} int main()
{
int N, L; while(scanf("%d%d", &N, &L) != EOF)
{
int i, k=0; for(i=0; i<N; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
if(p[k].y>p[i].y || (p[k].y==p[i].y && p[k].x>p[i].x))
k = i;
}
swap(p[0], p[k]);
sort(p+1, p+N, cmp);
Graham(N); double ans = Dist(p[sta[0]],p[sta[top]]) + 2*PI*L; for(int i=0; i<top; i++)
ans += Dist(p[sta[i]], p[sta[i+1]]); printf("%d\n", (int)(ans+0.5));
} return 0;
}
Wall - POJ 1113(求凸包)的更多相关文章
- POJ 1113 Wall(Graham求凸包周长)
题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...
- poj 3525 求凸包的最大内切圆
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3640 ...
- 凸包入门(Graham扫描法)(A - Wall POJ - 1113)
题目链接:https://cn.vjudge.net/contest/276359#problem/A 题目大意:有一个国王,要在自己的城堡周围建立围墙,要求围墙能把城堡全部围起来,并且围墙距离城堡的 ...
- POJ 2187 求凸包上最长距离
简单的旋转卡壳题目 以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离 这里求的是距离的平方,所有过程都是int即可 #include <iostream> #includ ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- POJ 1113 Wall 求凸包的两种方法
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31199 Accepted: 10521 Descriptio ...
- 计算几何--求凸包模板--Graham算法--poj 1113
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28157 Accepted: 9401 Description ...
- POJ 1113 Wall【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- list集合中指定字段去重
在开发中,有时会需要指定字段去重,以下为实现方法: 假设有个房地产权的类,其中宗地代码ZDDM值重复,而我们在前端页面显示时,只需要一条数据,因为公共字段都一样: IEqualityComparer需 ...
- ERROR ITMS-90167: "No .app bundles found in the package"
http://stackoverflow.com/questions/37838487/error-itms-90167-no-app-bundles-found-in-the-package 简单说 ...
- 嵌入式web server——Goahead移植要点
前言 在嵌入式设备中,在没有液晶显示的情况下,可以使用web来访问设备,查看设备的运行状态以及进行参数设置,类似于路由器设置.网上有很多关于各种web server的优劣的评论,在此不讨论,只是介绍其 ...
- destoon代码从头到尾捋一遍
destoon® B2B网站管理系统(以下简称destoon)由西安嘉客信息科技有限责任公司独立研发并推出,对其拥有完全知识产权,中国国家版权局计算机软件著作权登记号:2009SR037570. 系统 ...
- Android Handler、Lopper消息驱动机制
Android应用程序是通过消息来驱动的,系统为每一个应用程序维护一个消息队例(MesageQueue),应用程序的主线程不断地从这个消息队例中获取消息(Mesage),然后对这些消息进行处理(Han ...
- Android中基于Socket的网络通信
1. Socket介绍 2. ServerSocket的建立与使用 3. 使用ServerSocket建立聊天服务器-1 4. 使用ServerSocket建立聊天服务器-2 5. 在Android中 ...
- 转: QtCreator调试程序时GDB崩溃
这个情况出现在QtCreator的2.5版以上,是由于新版QtCreator至少需要7.2 IIRC版的GDB.可以到:http://builds.qt-project.org/job/gdb-win ...
- EQueue 2.3.2
EQueue 2.3.2版本发布(支持高可用) 前言 前段时间针对EQueue的完善终于告一段落了,实在值得庆祝,自己的付出和坚持总算有了成果.这次新版本主要为EQueue实现了集群功能,基本实现了B ...
- 《将博客搬至CSDN》 分类: 勉励自己 2014-09-05 14:29 43人阅读 评论(0) 收藏
搬家啦,上博客园关注我哦http://www.cnblogs.com/AsuraRoute 版权声明:本文为博主原创文章,未经博主允许不得转载.
- 如何与 DevOps 为伍?
DevOps 是一个席卷 IT 界的新术语.但它究竟是什么,南非的公司们如何利用它来加快高品质应用程序的开发速度?国外知名博客作者凯西·吉布森找到了一些答案. 其实 DevOps 这个词已经火了一段时 ...