Wall--POJ1113(极角排序+求凸包)
http://poj.org/problem?id=1113
题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l
分析 :现在就是求凸包的周长然后再加上一个圆的周长

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue> using namespace std;
#define N 1005
#define pi acos(-1.0)
#define ESP 1e-8 int s[N]; struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
Point operator - (const Point &temp)const
{
return Point(x-temp.x,y-temp.y);
}
Point operator + (const Point &temp)const
{
return Point(x+temp.x,y+temp.y);
}
bool operator == (const Point &temp)const
{
return (x==temp.x && y==temp.y);
}
double operator * (const Point &temp)const
{
return (x*temp.x+y*temp.y);
}
int operator ^ (const Point &temp)const{
double t=x*temp.y-y*temp.x;
if(t>ESP)
return ;
if(fabs(t)<ESP)
return ;
return -;
}
}a[N]; double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} int cmp(Point a1,Point a2)
{
int t=((a1-a[])^(a2-a[]));
if(t==)
return dist(a1,a[])<dist(a2,a[]);
else
return t>;
}
int top;
void Graham(int n)///求凸包
{
s[]=;
s[]=;
top=;
for(int i=;i<n;i++)
{
while(top> && ((a[i]-a[s[top]])^(a[s[top-]]-a[s[top]]))<=)
top--;
s[++top]=i;
} } int main()
{
int n,l;
while(scanf("%d %d",&n,&l)!=EOF)
{
memset(s,,sizeof(s));
int k=;
for(int i=;i<n;i++)
{
scanf("%lf %lf",&a[i].x,&a[i].y);
if(a[i].y<a[k].y || (a[i].y==a[k].y && a[i].x<a[k].x))
k=i;
}
swap(a[],a[k]);
sort(a+,a+n,cmp); Graham(n);
double C=;
for(int i=;i<=top;i++)
{
C+=dist(a[s[i]],a[s[i-]]);
}
C+=dist(a[s[]],a[s[top]]);
C+=*pi*l;
printf("%.0lf\n",C);
}
return ;
}
Wall--POJ1113(极角排序+求凸包)的更多相关文章
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- L3-021 神坛(极角排序求三角形最小面积)
在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面 ...
- hdu 1348:Wall(计算几何,求凸包周长)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Wall - POJ 1113(求凸包)
题目大意:给N个点,然后要修建一个围墙把所有的点都包裹起来,但是要求围墙距离所有的点的最小距离是L,求出来围墙的长度. 分析:如果没有最小距离这个条件那么很容易看出来是一个凸包,然后在加上一个最小距离 ...
- poj 1696 极角排序求最长逆时针螺旋线
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4970 Accepted: 3100 Descrip ...
- hdu5785(极角排序求所有锐角钝角个数)
做法很显然,求出所有的锐角和钝角就能求出有多少个锐角三角形了. 我用了愚钝的方法,写了两三个小时... 看了下别人简单的代码.学习了下做法. sort(temp+,temp+cnt+);//排序 Fo ...
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
- POJ 1113 Wall 求凸包的两种方法
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31199 Accepted: 10521 Descriptio ...
随机推荐
- Web服务器禁止range请求
range: 请求一般是多线程下载的客户端程序使用 在httpd.conf中增加下面的配置,可以禁止range请求: RewriteEngine onRewriteCond %{HTTP:Range} ...
- strong & weak
Here is a quick summary: A strong reference will keep the object it points to from being deallocated ...
- Windows、VS 与 .net
原文地址:https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx .NET Framework version CLR ver ...
- Libevent 定时器
先摘一点网上的介绍 libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用select.epoll.kqueue等系统调用管理事件机制.著名分布式缓存软件 ...
- 常用vim设置
set tabstop=4set shiftwidth=4set expandtabset hlsearchset cindent set autoindent set tabstop=4是设TAB宽 ...
- CSS3基础01
一.选择器: 分为关系选择器 ,属性选择器 ,伪类选择器 1.1关系选择器 后代选择器 ul li 选择所有的后代元素 子代选择器 ul > li 选择ul的儿子 紧邻选择器 .b ...
- System.DateTime.Now的内容
?System.DateTime.Now{2016/10/09 15:19:12} Date: {2016/10/09 0:00:00} dateData: 985948826838121 ...
- 关于sql注入
删除表,先猜表名,可以使用下面的语名: Select * from A where A.a = ‘testdata’; drop table A---’; If a field only allow ...
- 2016.02.14 总结JS事件
今天主要总结JS事件的基本知识以及使用技巧,并作出相应的DEMO.
- WebClient异步下载文件
namespace ConsoleAppSyncDownload{ class Program { static void Main(string[] args) { ...