POJ 1113 Wall 凸包

POJ 1113 Wall 凸包

大家好,又见面了,我是全栈君。

Wall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 29183   Accepted: 9768

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.



POJ 1113 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

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

struct node
{
	double x,y;
}a[1005],b[1005];

double cmp(node n,node m)
{
	if(n.x != m.x)   
		return  n.x < m.x;
	else
		return  n.y < m.y;
}

double Cross(node a,node b,node c)
{
	return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}

double dis(node a,node b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int CH(node* a,int n,node* b)
{
	sort(a,a+n,cmp);
	int m=0,i;
	for(i=0;i<n;i++)
	{
		while(m > 1 && Cross(b[m-2],b[m-1],a[i]) < 0)
			m--;
		b[m++]=a[i];
	}


	int k=m;
	for(i=n-2;i>=0;i--)
	{
		while(m > k && Cross(b[m-2],b[m-1],a[i]) < 0)
			m--;
		b[m++]=a[i];
	}
	
	if(n >1)  m--;
	return m;
}

int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		if(n==0)   break;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));

		int i,j;
		for(i=0;i<n;i++)
		{
			cin>>a[i].x>>a[i].y;
		}
		

		int k=CH(a,n,b);
		double s=0;
		for(i=1;i<k;i++)
			s+=dis(b[i-1],b[i]);
		s+=dis(b[0],b[k-1])+3.1415927*m*2;
		printf("%.0lf\n",s);   

	}

	return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115553.html原文链接:https://javaforall.net

(0)
上一篇 2022年2月2日 下午9:00
下一篇 2022年2月2日 下午9:00


相关推荐

  • PyQt5+Qt designer实战

    PyQt5+Qt designer实战PyQt5 Qtdesigner 制作计算器配置说明 Anaconda4 2 0 64 bit Python3 5 2 首先 在 Qtdesigner 里面设计界面 打开 Qtdesigner 后 设计界面如下所示 保存为 clat ui 然后将其转为 py 文件 之后会生产 clat py 文件 打开后 代码如下 coding utf 8

    2026年3月26日
    3
  • Linux EXT4文件系统简介

    Linux EXT4文件系统简介在先前有关 Linux 文件系统的文章中 我写了 Linux 文件系统的介绍以及一些更高级的概念 例如 一切都是文件 我想更详细地了解 EXT 文件系统的细节 但是首先让我们回答以下问题 什么是文件系统 文件系统包括以下所有内容 数据存储 任何文件系统的主要功能都应该是存储和检索数据的结构化场所 命名空间 一种命名和组织方法 提供命名和结构化数据的规则 安全模型 一种用于定

    2026年3月18日
    1
  • 告别Token焦虑!2026年零基础OpenClaw+MemOS部署,省Token,长期记忆准确率提升33.5%

    告别Token焦虑!2026年零基础OpenClaw+MemOS部署,省Token,长期记忆准确率提升33.5%

    2026年3月13日
    5
  • Java实现自定义注解

    Java实现自定义注解前言 nbsp nbsp nbsp nbsp 上一篇文章介绍了注解的一些基本知识 这次来介绍下如何实现自定义注解及注解如何使用 正文 nbsp nbsp nbsp nbsp 注解是一种能被添加到 java 源代码中的元数据 方法 类 参数和包都可以用注解来修饰 注解可以看作是一种特殊的标记 可以用在方法 类 参数和包上 程序在编译或者运行时可以检测到这些标记而进行一些特殊的处理

    2026年3月19日
    1
  • Java修饰符总结

    Java修饰符总结Java 修饰符下表列出所有 Java 修饰符 并说明了各自能修饰的 Java 结构种类和作用修饰符用于意义 abstract 类接口方法这个类不能被实例化 而且可能包含未实现的方法所有接口都是抽象的 声明接口时这个修饰符是可选的这个方法没有主体 主体由子类提供 签名后面是一个分号 所在的类必须也是抽象的 default 方法这个接口方法的实现是可选的

    2026年3月17日
    2
  • 使用phpmyadmin浏览库结构很卡的问题的解决方案

    使用phpmyadmin浏览库结构很卡的问题的解决方案

    2022年3月2日
    38

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号