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 ...
随机推荐
- oracle 创建表空间
--创建数据表空间 create tablespace hcm logging datafile 'G:\oracle\product\10.2.0\oradata\orcl\mydata.dbf' ...
- ios隐藏键盘
1.点击页面空白处隐藏键盘 给viewController里面复写-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法,在 ...
- vi编辑器的简单使用
Esc --进入扩展模式 a i o --进入插入模式 w --保存 q --退出 wq!--强制保存退出 p --粘贴 前面加数字表示粘贴多少行 u --复原前一个操作 Carl+r - ...
- stdio.h----标准的输入输出函数
C++兼容了stdio.h函数,其用法和c一样. 命令形式 #include <stdio.h>; 1.
- typedef struct 结构体
typedef struct _TTTT_ { int i; }TT_TT; 定义变量如下: struct _TTTT_ NewTT;方法1 TT_TT NewTT;方法2 是声明和定义 ...
- 56. Edit Distance && Simplify Path
Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert ...
- 五、selecting with the API
1. 命令通常从selection list中得到input, 调用MGlobal::getActiveSelectionList(MSelectionList &dest, bool ord ...
- jquery常用正则表达式
1.邮箱验证正则表达式:/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/ 2.手机验证正则表达式:/^ ...
- leetcode-【简单题】Two Sum
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- flask一些资料
http://shulhi.com/celery-integration-with-flask/ https://jeffknupp.com/blog/2014/01/29/productionizi ...