POJ 1113 Wall【凸包周长】
题目:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 26219 | Accepted: 8738 |
Description
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 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
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
Hint
Source
题意:
N个点代表城堡的坐标,
要求城堡任意一点到城墙的距离恰好 L 远建立城墙,求精确的长度
注意:结果四舍五入+0.5取整即可
思路:
/************************************************
Accepted 220 KB 0 ms C++ 1462 B 2013-07-27 15:46:32
题意:按照顺时针顺序给你N个点的坐标,再给你一个长度L
N个点代表城堡的坐标,
要求城堡任意一点到城墙的距离恰好 L 远建立城墙,求精确的长度
注意:结果四舍五入+0.5取整即可
思路:凸包周长+以 L 为半径圆的周长
**********************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; const int maxn = 1000+10;
const double PI = 3.1415926535;
int n,m;
int L; struct Point{
double x,y;
Point(){}
Point(double _x, double _y)
{
x = _x;
y = _y;
} Point operator -(const Point &B) const
{
return Point(x-B.x, y-B.y);
}
}p[maxn], ch[maxn]; bool cmp(Point A, Point B)
{
if(A.x == B.x) return A.y < B.y;
return A.x < B.x;
} double dist(Point A, Point B)
{
return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
} double Cross(Point A, Point B) /**叉积*/
{
return A.x*B.y - A.y*B.x;
} void ConvexHull() /**求凸包*/
{
sort(p,p+n,cmp);
m = 0;
for(int i = 0; i < n; i++)
{
while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
int k = m;
for(int i = n-2; i >= 0; i--)
{
while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
if(n > 1) m--;
} int solve()
{
ConvexHull();
double ans = 0;
ch[m] = ch[0]; /**边界处理*/
for(int i = 0; i < m; i++) /**凸包周长*/
ans += dist(ch[i], ch[i+1]);
ans += PI*L*2; /** 圆周长*/
return (int)(ans+0.5); /**四舍五入+0.5取整*/
} int main()
{
while(scanf("%d%d", &n,&L) != EOF)
{
for(int i = 0; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
printf("%d\n", solve());
}
return 0;
}
POJ 1113 Wall【凸包周长】的更多相关文章
- POJ 1113 Wall 凸包 裸
LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...
- poj 1113 Wall 凸包的应用
题目链接:poj 1113 单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...
- poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43274 Accepted: 14716 Descriptio ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- POJ 1113 Wall(Graham求凸包周长)
题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...
- POJ 1113 Wall (凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- 题解报告:poj 1113 Wall(凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
随机推荐
- java中map的应用
map是键值对的集合接口,需要存储两个字段有联系的字段时可以使用这个. 1.查找字符串数组重复次数最多的字符串的重复次数 思路:使用map键值对存储,key值存数字符串,value存储出现的次数 Ma ...
- 【ecshop---新增包邮卡功能】
一:需求分析 项目组要求新增类似虚拟卡的包邮卡,用户获得包邮卡的方式包括后台发送和前台自助充值.包邮卡有使用期限.订单使用包邮卡免除邮费.可以和其他优惠活动同时进行! 二:开发功能点 后台:新增包邮卡 ...
- Angular 学习笔记——ng-Resource1
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- PS如何拉倒影效果
1 复制图形(一般是文字)并垂直翻转得到倒影的初步样子(最好倾斜一下,看起来逼真一些)就像下面的迅雷的样子.记住要栅格化文字. 2 用魔棒工具抠除原来的颜色,只剩下空的选区. 3 拉渐变
- PHP 在源代码中实现换行使得页面源代码更精致美观
常量 : PHP_EOL 换行实例: <? php echo $this->doctype($this->doctype) . PHP_EOL;?> <html> ...
- iOS开发--Mac下server搭建
前言 对于Mac电脑的认识.我一直停留在装B神器的意识上.就在前两天我彻底改变了庸俗的看法,当时忙着写毕业设计.苦于iOS开发没有server, 数据都是从网上抓取或本地plist文件,感觉不够高大上 ...
- odoo12新特性: 会计改进
改进分析会计 分析会计层级结构 分析分配 分析分录增加了表格视图 ============== SPECIFICATIONS ============== a. Hierarchy - Cr ...
- odoo分析会计
odoo财务会计凭证录入时,支持 在凭证行 输入 分析账户和 分析标签 如果凭证行设置了 分析账户或者分析标签, 则在会计凭证过账的时候, 在分析会计功能建立 分析会计分录 其中, 如果设置了分析账户 ...
- Eclipse.ini参数设置
最近Eclipse不知道是由于项目过多还是其他原因导致Eclipse进程容易卡死,一卡死Workspace保存出错,项目就全都不见了,又得重新导入...鉴于此原因,自己也上网查询了相关资料,现整理如下 ...
- js从$scope外部调用$scope内部函数,跨js调用非全局函数
scope内部函数定义 //定位 $scope.LocateByPoint = function (x,y) { if(!x || !y) { window.alert("GPS坐标不存在, ...