当前位置: 首页 > 编程日记 > 正文

【POJ1113】Wall(凸包)

【题目】

Description

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall. 

Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements. 

The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.

Input

The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle. 

Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.

Output

Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.

Sample Input

9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200

Sample Output

1628

代码如下:
 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 #define Maxn 1010
10 
11 struct Point
12 {
13     double x,y;
14     Point(double x=0,double y=0):x(x),y(y) {}
15 };
16 
17 typedef Point Vector;
18 Point p[Maxn];
19 
20 int n,l;
21 const double pi=3.1415926535898;
22 
23 double myabs(double x) {return x<0?-x:x;}
24 
25 const double eps=1e-10;
26 int dcmp(double x)//判断正负和零
27 {
28     if(myabs(x)<eps) return 0;
29     else return x<0?-1:1;
30 }
31 Vector operator - (Point A,Point B) {return Vector(A.x-B.x,A.y-B.y);}
32 
33 double Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;}
34 double Cross(Vector A,Vector B) {return A.x*B.y-A.y*B.x;}
35 double Length(Vector A) {return sqrt(Dot(A,A));}
36 
37 
38 bool cmp(Point x,Point y) {return dcmp(x.x-y.x)==0?(x.y<y.y):(x.x<y.x);}
39 Point ch[Maxn];int len=0;
40 
41 void covexhull()
42 {
43     for(int i=1;i<=n;i++)
44     {
45         while(len>1&&Cross(ch[len]-ch[len-1],p[i]-ch[len-1])<=0) len--;
46         ch[++len]=p[i];
47     }int k=len;
48     for(int i=n-1;i>=1;i--)
49     {
50         while(len>k&&Cross(ch[len]-ch[len-1],p[i]-ch[len-1])<=0) len--;
51         ch[++len]=p[i];
52     }
53     if(n>1) len--;
54 }
55 
56 double PolygonLength()
57 {
58     double L=0;
59     for(int i=2;i<=len;i++)
60         L+=Length(ch[i]-ch[i-1]);
61     L+=Length(ch[1]-ch[len]);
62     return L;
63 }
64 
65 int main()
66 {
67     scanf("%d%d",&n,&l);
68     for(int i=1;i<=n;i++)
69     {
70         scanf("%lf%lf",&p[i].x,&p[i].y);
71     }
72     sort(p+1,p+1+n,cmp);
73     covexhull();
74     printf("%.0f\n",PolygonLength()+pi*l*2);
75     return 0;
76 }
[POJ1113]

2016-04-28 19:32:02

转载于:https://www.cnblogs.com/Konjakmoyu/p/5443953.html

相关文章:

matlab小波分析工具箱原理与应用_补充:频域特征值提取的MATLAB代码实现(小波分析)...

之前的文章信号频域分析方法的理解&#xff08;频谱、能量谱、功率谱、倒频谱、小波分析&#xff09;中提到了离散小波分解的例子&#xff0c;其参考代码如下&#xff1a;t_s 结果如下&#xff1a;原始信号离散小波分析结果左侧四行是1~4阶的近似信号&#xff0c;右侧四行是1~4…

【ReactiveX】基于Golang pmlpml/RxGo程序包的二次开发

基于Golang pmlpml/RxGo程序包的二次开发【阅读时间&#xff1a;约20分钟】一、ReactiveX & RxGo介绍1.ReactiveX2.RxGo二、系统环境&项目介绍1.系统环境2.项目的任务要求三、具体程序设计及Golang代码实现1.程序设计2.filteringOperator数据结构、op函数与newFilterOb…

python dataframe 中位数_python下的Pandas中DataFrame基本操作(一),基本函数整理

pandas作者Wes McKinney 在【PYTHON FOR DATA ANALYSIS】中对pandas的方方面面都有了一个权威简明的入门级的介绍&#xff0c;但在实际使用过程中&#xff0c;我发现书中的内容还只是冰山一角。谈到pandas数据的行更新、表合并等操作&#xff0c;一般用到的方法有concat、join、…

对输入框以及选择框集体的数据检验

对于一个档案输入框&#xff0c;有很多输入框是需要输入数据的&#xff0c;但有时候我们会在输入的时候遗留一些必填的项&#xff0c;如果不做数据校验&#xff0c;这时候点击保存按钮&#xff0c;就悲剧了&#xff0c;报错不说&#xff0c;我们前面填写的数据也就没有了。 所以…

CentOS Docker安装配置部署Golang web helloworld

目录【阅读时间&#xff1a;约5分钟】一、Docker简介二、Docker的安装与配置【CentOS环境】三、Docker部署Golang web helloworld四、Docker与虚拟机的区别五、吐槽一、Docker简介 Docker 是一个开源的应用容器引擎&#xff0c;让开发者可以打包他们的应用以及依赖包到一个可移…

[CareerCup] 2.4 Partition List 划分链表

2.4 Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. LeetCode上的原题&#xff0c;请参见我之前的博客Partition List 划分链表。

一条命令下载google壁纸,含错误解决方法

该命令是从google图片搜索上搜索wallpaper的大尺寸图片&#xff0c;匹配其中的jpg文件进行下载。 #!/bin/bash for i in {1..10}; do for url in $(wget -O- -U "" "http://images.google.com/images?imgszxxlarge&hlen&qwallpaper&saN&s…

git config —global_Git多用户配置

备注&#xff1a;如下的操作&#xff0c;Windows系统建议在Git bash工具里操作。如下操作的原理&#xff0c;建议查阅官方文档。Git - Reference1.取消全局设置的用户信息。Git命令&#xff1a;$ git config --global --unset user.name $ git config --global --unset user.em…

中级实训总结报告

目录【阅读时间&#xff1a;约30分钟】中级实训总结报告姓名&#xff1a;隐藏敏感信息 学号&#xff1a;隐藏敏感信息一、阶段1&#xff1a;项目启动1、Vi/Vim2、Java3、Ant4、Junit5、SonarQube6、 编译运行BugRunner二、阶段2&#xff1a;基本任务1. part2的工作&#xff08;…

PHP解决方案@黑名单过滤

为什么80%的码农都做不了架构师&#xff1f;>>> 方案解决目标&#xff1a;对一些黑名单进行过滤处理 function is_spam($text, $file, $split :, $regex false){ $handle fopen($file,rb); $contents fread($handle, filesize($file)); fclose($handle); $lines …

Ubuntu 12.04下玩转终端管理器Byobu

简介 很多Linux高手都喜欢使用screen命令&#xff0c;screen命令可以使你轻松地使用一个终端控制其他终端。尽管screen本身是一个非常有用的工具&#xff0c;byobu作为screen的增强版本&#xff0c;比screen更加好用而且美观&#xff0c;并且提供有用的信息和快捷的热键。 想象…

python字典排序方法_Python字典的排序方法一则

今天需要对Python的字典进行排序&#xff0c;以获得有效的时间序列&#xff0c;采用了如下方法&#xff1a; 首先生成一个示例字典&#xff1a; >>> range_a random.sample(range(0, 10), 10) >>> range_b random.sample(range(10, 20), 10) >>> …

encodeURI 和 encodeURIComponent

保留字符 &#xff08;reserved characters&#xff09;&#xff1a;这类字符是URI中的保留关键字符&#xff0c;它们用于分割URI中的各个部分。这些字符是&#xff1a;";" | "/" | "?" | ":" | "" | "&&quo…

基于Golang的简单web服务程序开发——CloudGo

基于Golang的简单web服务程序开发——CloudGo【阅读时间&#xff1a;约10分钟】一、概述二、系统环境&项目介绍1.系统环境2.项目的任务要求&#xff08;1&#xff09;基本要求&#xff08;2&#xff09;扩展要求三、具体程序设计及Golang代码实现1.预先准备2.CloudGoClient…

Android Studio创建项目

版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主允许不得转载。 https://blog.csdn.net/u010046908/article/details/47000873 创建项目 首先&#xff0c;先指出Android Studio中的两个概念。 Project和 Module。在Android Studio中&#xff0c; Project的真实含义…

Weiss的数据结构与算法分析(C++版)源码编译说明

最近尝试编译Weiss的那本数据结构与算法分析&#xff08;C版&#xff09;提供的源代码时&#xff0c;遇到一些问题&#xff0c;特记录如下&#xff1a;考虑到该书提供的代码是使用模板技术较多&#xff0c;这在提供简洁代码的同时&#xff0c;也给源码的编译带来了一些问题。因…

latex 中文_【小白向】LaTeX 中文入门

注&#xff1a;本文尚未撰写完毕&#xff0c;先暂存一下~(2020/06/27)参考学习路线[1]如何从零开始&#xff0c;入门 LaTeX&#xff1f; 孟晨 1. 卸载 CTeX 套装&#xff0c;安装 TeX Live原因及教程见&#xff1a;TeX Live 下载及安装说明2. 看完&#xff1a;一份其实很短的 L…

物联网兴起 嵌入式系统安全日益受关注

随着越来越多设备连接到互联网&#xff0c;专家们担心嵌入式系统将给企业带来严重安全风险&#xff0c;而很多企业还没有意识到这种风险或者无法缓解这种风险…… 随着越来越多设备连接到互联网&#xff0c;专家们担心嵌入式系统将给企业带来严重安全风险&#xff0c;而很多企业…

【Golang源码分析】Go Web常用程序包gorilla/mux的使用与源码简析

目录【阅读时间&#xff1a;约10分钟】一.概述二.对比: gorilla/mux与net/http DefaultServeMux三.简单使用四.源码简析1.NewRouter函数2.HandleFunc函数设置路由的HTTP方法设置路由的域名限制HTTP 方案设置路径前缀和子路由3.PathPrefix函数五.References一.概述 gorilla/mux…

FileMaker中的腳本觸發器學習筆記

脚本触发器 **脚本触发器是始终绑定到用户布局接口。对于数据表或者字段。只有在而已接口才能触发。**如果某一个布局或者对象上包含触发器&#xff0c;则其右下角会有触发器图标**当触发一个事件时&#xff0c;有且仅有一个触发器会被执行.布局级别的触发器**ONRECORDLOAD :加…

vim学习笔记(四)

下面是我的最近更新&#xff0c;差点删除。 下面的笔记摘自vimtutor。<CR>表示回车 删除命令 在normal模式下&#xff1a; de 删除一个单词&#xff0c;不包含空格 dw 删除一个单词&#xff0c;包含空格 dd 删除当前行 1,10d 删除指定行&#xff0c;第1到10行 ndd…

文件和缓存项目依赖

文件和缓存项目依赖 要创建缓存依赖&#xff0c;你需要创建一个 CacheDependency 对象并在添加依赖的缓存项目时使用它。例如&#xff0c;下面的代码创建一个缓存项目&#xff0c;它在一个 XML 文件被修改、删除、覆盖时自动从缓存中移除&#xff1a; CacheDependency prodDepe…

python函数的基础知识_Python入门基础知识点(函数进阶)

动态参数&#xff1a; 动态接收位置参数&#xff1a; def eat(*args): #在形参位置&#xff0c;*叫做聚合 print(我想吃,args) eat(大米饭,中米饭,小米饭) #收到的结果是一个tuple元祖 动态接收参数的时候要注意: 动态参数必须在位置参数后面&#xff0c;否则&#xff1a; def …

【CentOS】利用Kubeadm部署Kubernetes (K8s)

【CentOS】利用Kubeadm部署Kubernetes &#xff08;K8s&#xff09;【阅读时间&#xff1a;约10分钟】一、概述二、系统环境&项目介绍1.系统环境2.项目的任务要求三、具体实验流程1 系统准备2 安装常用包3 使用aliyun源安装docker-ce4 安装kubectl、kubelet、kubeadm5 初始…

HttpClient4.4 登录知乎(详细过程)

引言 HttpClient是java语言下一个支持http协议的客户端编程工具包&#xff0c;它实现了HTTP协议的所有方法&#xff0c;但是不支持JS渲染。我们在做一些小玩意时&#xff0c;有可能需要登录某些网站获取信息&#xff0c;那么HttpClient就是你的好帮手&#xff0c;废话不多说&am…

vim学习笔记(一)

&#xff1a;vertical sfind 垂直分隔窗口(vsf)&#xff0c;但是两个窗口的内容完全相同。在编辑的时候&#xff0c;内容也完全相同&#xff0c;如果要关闭一个窗口&#xff0c;输入&#xff1a;exit即可&#xff1a;buffers 显示整个缓冲区列表ndG 删除从当前行到指定n行中的…

Retrofit源码研究

2016-05-06 15:35:27 最近抽空研究了一下Retrofit源码&#xff0c;包括API使用、源码结构、使用到的设计模式、SDK的架构设计、作者设计/实现思路等&#xff0c;会形成一系列文章。 以前Retrofit还是1.9的时候&#xff0c;简单的写过一篇文章&#xff0c;简单研究下Retrofit&am…

wpf窗口向左向上_PaperWM:GNOME 下的平铺窗口管理

我使用 Gnome 已有很长时间了&#xff0c;但是我仍然有点想念平铺窗口管理器。六个月前&#xff0c;一个朋友告诉我有关 PaperWM 的消息&#xff0c;它使你可以在 Gnome 中平铺窗口&#xff01;我立即安装了它&#xff0c;并从那时起我一直在使用它。-- Julia Evans(作者)当我开…

Docker的安装、镜像源更换与简单应用

Docker的安装、镜像源更换与简单应用【阅读时间&#xff1a;约20分钟】一、概述二、系统环境&项目介绍1.系统环境2.项目的任务要求三、Docker的安装四、Docker的简单应用1. 运行第一个容器2. Docker基本操作3. MySQL与容器化3.1 拉取MySQL镜像3.2 构建docker镜像3.3 MySQL容…

vim学习笔记(三)

1.vim的配置文件在哪里&#xff1f;在normal模式下输入:echo $VIMVim的主配置文件为vimrc文件&#xff0c;它分为两个版本&#xff1a;global和personal&#xff0c;其中前者一般在/usr/share/vim/vimrc&#xff0c;后者一般在~/.vimrc,它是一个隐藏文件找到home目录的方法:ech…