POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包。
初次提交被坑得很惨,在GDB中可以完美运行A掉,到OJ上就频频RE(此处应有黑人问号)
后来发现了问题,原因是玩杂耍写了这样的代码
struct point {
int x, y;
point (){
scanf("%d%d", &x, &y);
}
...
}pt[MAXN];
于是乎,在swap
void swap(point &a, point &b){
point t = a;
a = b;
b = t;
}
的时候临时变量把数据读进去了,GG
//Ps. 我感觉这个代码高亮比上次的好看
//POJ1113
//凸包
//AC 2016.10.13 #include "cstdio"
#include "cstdlib"
#include "cmath"
#include "iostream"
#define MAXN 1010
const double pi = acos(-1.0); double sqr(double x){
return x * x;
} struct point {
int x, y;
point (){}
point (int X, int Y): x(X), y(Y) {}
double norm(){
return sqrt(sqr(x) + sqr(y));
}
friend bool operator < (const point &p1, const point &p2){
return (p1.x < p2.x)||(p1.x == p2.x)&&(p1.y < p2.y);
}
friend bool operator > (const point &p1, const point &p2){
return (p1.x > p2.x)||(p1.x == p2.x)&&(p1.y > p2.y);
}
friend point operator >> (const point &p1, const point &p2){
return point(p2.x - p1.x, p2.y - p1.y);
}
friend int operator ^ (const point &p1, const point &p2){
return p1.x * p2.y - p1.y * p2.x;
}
}pt[MAXN]; void swap(point &a, point &b){
point t = a;
a = b;
b = t;
} int main(){
int n, l;
freopen("fin.c", "r", stdin);
scanf("%d%d", &n, &l);
for (int i = 0; i < n; i++){
scanf("%d%d", &pt[i].x, &pt[i].y);
for (int j = i; j && (pt[j - 1] > pt[j]); j--)
swap(pt[j - 1], pt[j]);
}
int cur = 0;
double res = 0;
while (1){
int tmp = - 1;
for (int i = 0; i < n; i++)
if (i != cur){
if (tmp == - 1)
tmp = i;
else if (((pt[cur] >> pt[i]) ^ (pt[cur] >> pt[tmp])) > 0)
tmp = i;
}
res += (pt[cur] >> pt[tmp]).norm();
cur = tmp;
if ((tmp == - 1)||(!tmp)) break;
}
printf("%d\n", (int)(res + 2 * pi * l + 0.5));
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(凸包裸题)(记住求线段距离的时候是点积,点积是cos)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43274 Accepted: 14716 Descriptio ...
- 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 ...
- POJ 1113 Wall(凸包)
[题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...
- POJ 1113 Wall 求凸包
http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...
- POJ 1113 Wall 求凸包的两种方法
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31199 Accepted: 10521 Descriptio ...
随机推荐
- 【转载】IIS7.5(经典模式)访问静态资源(.css和.js文件)提示:未能执行 URL
IIS7.5(经典模式)静态资源(.css和.js文件)提示:未能执行 URL “/”应用程序中的服务器错误. 未能执行 URL. 说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪 ...
- Java 异步处理简单实践
Java 异步处理简单实践 http://www.cnblogs.com/fangfan/p/4047932.html 同步与异步 通常同步意味着一个任务的某个处理过程会对多个线程在用串行化处理,而异 ...
- SQL 查询某个表被哪些存储过程使用到
--1.查询某个表被哪些存储过程使用到 : select distinct object_name(id) from syscomments where id in (select object_id ...
- php命令传参
1.url方式 $param = array(); if ($argc > 1) { parse_str ( $argv [1], $param ); foreach ( $param as $ ...
- Linxu IO测试软件
fio 安装 apt-get install fio fdisk -l Device Boot Start End Blocks Id System/dev/sda1 * 2048 968390655 ...
- Spring-RMI固定端口
Spring-RMI固定端口 最近接到一个需求项目所应用的RMI端口(数据传输端口)为随机指定的,项目要求对其端口固定,费劲周折找了很多资料,最后解决了问题. 其实解决问题的方法及其简单,只需要在 ...
- 解决ftp连接出现 无法从控制 Socket 读取。Socket 错误 = #10054。
ftp连接会显示以下错误信息 无法从控制 Socket 读取.Socket 错误 = #10054 或者是这样的信息 Opening data channel for directory list.T ...
- pandas入门
[原]十分钟搞定pandas 本文是对pandas官方网站上<10 Minutes to pandas>的一个简单的翻译,原文在这里.这篇文章是对pandas的一个简单的介绍,详细的介 ...
- div 居中
Found another solution: Just add position: relative; top: 50%; transform: translateY(-50%); to the i ...
- System.Web.HttpCompileException (0x80004005): (0): error CS0016: 未能写入输出文件
重新系统后,iis asp.net站点老是出现: System.Web.HttpCompileException (0x80004005): (0): error CS0016: 未能写入输出文件“c ...