POJ 1113 Wall 凸包 裸
题意:给出一个简单几何,问与其边距离长为L的几何图形的周长。
思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角)。看了黑书使用graham算法极角序求凸包会有点小问题,最好用水平序比较好。或者用Melkman算法
/** @Date : 2017-07-13 14:17:05
* @FileName: POJ 1113 极角序求凸包 基础凸包.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const double Pi = acos(-1.0);
struct point
{
int x, y;
point(){}
point(int _x, int _y){x = _x, y = _y;}
point operator -(const point &b) const
{
return point(x - b.x, y - b.y);
}
int operator *(const point &b) const
{
return x * b.x + y * b.y;
}
int operator ^(const point &b) const
{
return x * b.y - y * b.x;
}
}; double xmult(point p1, point p2, point p0)
{
return (p1 - p0) ^ (p2 - p0);
} double distc(point a, point b)
{
return sqrt((double)((b - a) * (b - a)));
} int n, l;
point p[N];
stack<int>s; int cmp(point a, point b)//以p[0]基准 极角序排序
{
int t = xmult(a, b, p[0]);
if(t > 0)
return 1;
if(t == 0)
return distc(a, p[0]) < distc(b, p[0]);
if(t < 0)
return 0;
} void graham()
{
while(!s.empty())
s.pop();
for(int i = 0; i < min(n, 2); i++)
s.push(i);
int t = 1;
for(int i = 2; i < n; i++)
{
while(s.size() > 1)
{
int p2 = s.top();
s.pop();
int p1 = s.top();
if(xmult(p[p1], p[p2], p[i]) > 0)
{
s.push(p2);
break;
}
}
s.push(i);
} } int main()
{
while(~scanf("%d%d", &n, &l))
{
int x, y;
int mix, miy;
mix = miy = INF;
int pos = -1;
for(int i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
p[i] = point(x, y);
if(miy > y || miy == y && mix > x)//注意选第一个点 是最左下方的
{
mix = x, miy = y;
pos = i;
}
}
swap(p[pos], p[0]);
sort(p + 1, p + n, cmp);
graham();
double ans = l * Pi * 2.0000;
int t = 0;
while(!s.empty())
{
ans += distc(p[t], p[s.top()]);
t = s.top();
s.pop();
}
printf("%d\n", (int)(ans + 0.500000));
}
return 0;
}
POJ 1113 Wall 凸包 裸的更多相关文章
- poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43274 Accepted: 14716 Descriptio ...
- 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【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- 2018.07.04 POJ 1113 Wall(凸包)
Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...
- POJ 1113 Wall(凸包)
[题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...
- POJ 1113 Wall 求凸包
http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...
随机推荐
- 缓存-MemoryCache Class
这是使用MemoryCache缓存的一个例子. private void btnGet_Click(object sender, EventArgs e) { ObjectCache cache = ...
- DPDK报文分类与访问控制
原创翻译,转载请注明出处. dpdk提供了一个访问控制库,提供了基于一系列分类规则对接收到的报文进行分类的能力.ACL库用来在一系列规则上执行N元组查找,可以实现多个分类和对每个分类查找最佳匹配(最高 ...
- Mysql中``和‘’的区别
两者在linux下和windows下不同,linux下不区分,windows下区分. 在windows下主要区别就是 单引号( ' )或双引号主要用于 字符串的引用符号 如: mysql> SE ...
- 201621123037 《Java程序设计》第12周学习总结
作业12-流与文件 标签(空格分隔): Java 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 答: 读取操作 从文件中读取: 1.字节流 InputStr ...
- Node.js系列——(3)连接DB
背景 node.js,有人称之为运行在服务器端的JavaScript.以往我们使用JavaScript时,都是依赖后端查询数据库并返回数据,而JavaScript只需要展示即可.问题来了,就不能绕开后 ...
- windows(32位 64位)下python安装mysqldb模块
windows(32位 64位)下python安装mysqldb模块 www.111cn.net 编辑:mengchu9 来源:转载 本文章来给各位使用在此windows系统中的python来安装一个 ...
- CPU测试--通过proc获取CPU信息
adb shell cat /proc/stat | grep cpu > totalcpu0 此处第一行的数值表示的是CPU总的使用情况,所以我们只要用第一行的数字计算就可以了.下表解析第一行 ...
- 【bzoj4709】[Jsoi2011]柠檬 斜率优化
题目描述 给你一个长度为 $n$ 的序列,将其分成若干段,每段选择一个数,获得 $这个数\times 它在这段出现次数的平方$ 的价值.求最大总价值. $n\le 10^5$ . 输入 第 1 行:一 ...
- [BZOJ1588][HNOI2002]营业额统计 无旋Treap
[HNOI2002]营业额统计 时间限制: 5 Sec 内存限制: 162 MB 题目描述 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以 ...
- 【JavaScript】函数表达式
一.前言 接着上一篇的内容,继续学习JavaScript. 二.内容 函数的声明 function functionName(arg0,arg1,arg2){ //函数体 } ...