题目链接:https://cn.vjudge.net/problem/POJ-1113

题意

给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长

思路

求得凸包的周长,再加上一个半径为L的圆的周长

提交过程

CE 注意某些OJ上cmath库里没有M_PI
AC

代码

#define PI 3.1415926
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const double eps=1e-10;
struct Point{
double x, y; Point(int x=0, int y=0):x(x), y(y) {}
// no known conversion for argument 1 from 'Point' to 'Point&'
Point operator + (Point p){return Point(x+p.x, y+p.y);}
Point operator - (Point p){return Point(x-p.x, y-p.y);}
Point operator * (double k){return Point(k*x, k*y);}
Point operator / (double k){return Point(x/k, y/k);}
bool operator < (Point p) const{return (x==p.x)?(y<p.y):(x<p.x);} // need eps?
bool operator == (const Point p) const{return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;}
double norm(void){return x*x+y*y;}
double abs(void){return sqrt(norm());}
double dot(Point p){return x*p.x+y*p.y;} // cos
double cross(Point p){return x*p.y-y*p.x;} // sin
};
struct Segment{Point p1, p2;};
struct Circle{Point o; double rad;};
typedef Point Vector;
typedef vector<Point> Polygon;
typedef Segment Line; int ccw(Point p0, Point p1, Point p2){
Vector v1=p1-p0, v2=p2-p0;
if (v1.cross(v2)>eps) return 1; // anti-clockwise
if (v1.cross(v2)<-eps) return -1; // clockwise
if (v1.dot(v2)<0) return 2;
if (v1.norm()<v2.norm()) return -2;
return 0;
} Point project(Segment s, Point p){
Vector base=s.p2-s.p1;
double k=(p-s.p1).cross(base)/base.norm();
return s.p1+base*k;
} Point reflect(Segment s, Point &p){
return p+(project(s, p)-p)*2;
} double lineDist(Line l, Point p){
return abs((l.p2-l.p1).cross(p-l.p1)/(l.p2-l.p1).abs());
} double SegDist(Segment s, Point p){
if ((s.p2-s.p1).dot(p-s.p1)<0) return Point(p-s.p1).abs();
if ((s.p1-s.p2).dot(p-s.p2)<0) return Point(p-s.p2).abs();
return abs((s.p2-s.p1).cross(p-s.p1)/(s.p2-s.p1).abs());
} bool intersect(Point p1, Point p2, Point p3, Point p4){
return ccw(p1, p2, p3)*ccw(p1, p2, p4)<=0 &&
ccw(p3, p4, p1)*ccw(p3, p4, p2)<=0;
} Point getCrossPoint(Segment s1, Segment s2){
Vector base=s2.p2-s2.p1;
double d1=abs(base.cross(s1.p1-s2.p1));
double d2=abs(base.cross(s1.p2-s2.p1));
double t=d1/(d1+d2);
return s1.p1+(s1.p2-s1.p1)*t;
} double area(Polygon poly){
double res=0; long long size=poly.size();
for (int i=0; i<poly.size(); i++)
res+=poly[i].cross(poly[(i+1)%size]);
return abs(res/2);
} int contain(Polygon poly, Point p){
int n=poly.size();
bool flg=false;
for (int i=0; i<n; i++){
Point a=poly[i]-p, b=poly[(i+1)%n]-p;
if (ccw(poly[i], poly[(i+1)%n], p)==0) return 1; // 1 means on the polygon.
if (a.y>b.y) swap(a, b);
if (a.y<0 && b.y>0 && a.cross(b)>0) flg=!flg;
}return flg?2:0; // 2 fo inner, 0 for outer.
} Polygon convexHull(Polygon poly){
if (poly.size()<3) return poly;
Polygon upper, lower;
sort(poly.begin(), poly.end());
upper.push_back(poly[0]); upper.push_back(poly[1]);
lower.push_back(poly[poly.size()-1]); lower.push_back(poly[poly.size()-2]);
for (int i=2; i<poly.size(); i++){
for (int n=upper.size()-1; n>=1 && ccw(upper[n-1], upper[n], poly[i])!=-1; n--)
upper.pop_back();
upper.push_back(poly[i]);
}
for (int i=poly.size()-3; i>=0; i--){
for (int n=lower.size()-1; n>=1 && ccw(lower[n-1], lower[n], poly[i])!=-1; n--)
lower.pop_back();
lower.push_back(poly[i]);
}
for (int i=1; i<lower.size(); i++)
upper.push_back(lower[i]);
return upper;
} int main(void){
int n, L;
double x, y; while (scanf("%d%d", &n, &L)==2 && n){
Polygon poly, hull;
for (int i=0; i<n; i++){
scanf("%lf%lf", &x, &y);
poly.push_back(Point(x, y));
}
hull=convexHull(poly); double ans=0;
for (int i=0; i<hull.size(); i++)
ans+=(hull[i]-hull[(i+1)%hull.size()]).abs();
printf("%.0f\n", ans+2*PI*L);
} return 0;
}
Time Memory Length Lang Submitted
47ms 652kB 3659 G++ 2018-08-01 11:23:54

POJ-1113 Wall 计算几何 求凸包的更多相关文章

  1. POJ 1113 Wall(计算几何の凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  2. POJ 1113 Wall 凸包 裸

    LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...

  3. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  4. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

  5. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  6. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

  7. POJ 1113 Wall 求凸包

    http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...

  8. POJ 1113 Wall(Graham求凸包周长)

    题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...

  9. POJ 1113 Wall【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

随机推荐

  1. Hihocoder1061-Beautiful String

    时间限制:10000ms单点时限:1000ms内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 or ...

  2. java开发移动端之spring的restful风格定义

    https://www.ibm.com/developerworks/cn/web/wa-spring3webserv/index.html

  3. WebAssembly学习(二):Windows10下WebAssembly C/C++编译环境的搭建与Hello World尝试

    首先,不论是在Windows.Linux还是Mac上,Webassembly的编译都是主要依赖于Emscripten SDK这个工具的.但是,在这里必须要吐槽一下,不论是WebAssembly官网.W ...

  4. [Atcoder Code Festival 2017 Qual A Problem D]Four Coloring

    题目大意:给一个\(n\times m\)的棋盘染四种颜色,要求曼哈顿距离为\\(d\\)的两个点颜色不同.解题思路:把棋盘旋转45°,则\((x,y)<-(x+y,x-y)\).这样就变成了以 ...

  5. [LUOGU]P3701 主席树(假的)

    有人恶意刷难度...就一个最大流模板... 但是题面吼啊2333 #include <iostream> #include <cstdio> #include <queu ...

  6. ansible 主机清单 /etc/ansible/hosts

    主机清单 [webservers] ansible01 ansible02 ansible03 ansible04 [root@ftp:/root] > ansible webservers - ...

  7. css所有属性(table,行列组)总结

    概述: CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明: CSS声明总是以分号(;)结束,声明组以大括号({})括起来: 一.注释: CSS注释以 "/*" 开始, ...

  8. 字符拆分存入Map计算单词的个数

    ///计算从命令行输入单词的种类与个数//Map<key,Value>Key-->单词:Value-->数量

  9. java 基础概念 -- 数组与内存控制

    问题1: Java在声明数组的过程中,是怎样分配内存的? 在栈内存中 建一个数组变量,再在堆内存中 建一个 数组对象.至于详细的内存分配细节,还得看 该初始化是 数组动态初始化 还是 数组静态初始化. ...

  10. 为什么选性别会导致兴趣都选中-vue

    为什么选性别会导致兴趣都选中-vue <%@ page language="java" import="java.util.*" pageEncoding ...