POJ 1113 Wall(凸包)
【题目链接】 http://poj.org/problem?id=1113
【题目大意】
给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度
【题解】
画图易得答案为凸包的周长加一个圆的周长。
【代码】
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
double EPS=1e-10;
const double PI=acos(-1.0);
double add(double a,double b){
if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
return a+b;
}
struct P{
double x,y;
P(){}
P(double x,double y):x(x),y(y){}
P operator + (P p){return P(add(x,p.x),add(y,p.y));}
P operator - (P p){return P(add(x,-p.x),add(y,-p.y));}
P operator * (double d){return P(x*d,y*d);}
double dot(P p){return add(x*p.x,y*p.y);} //点积
double det(P p){return add(x*p.y,-y*p.x);} //叉积
};
bool cmp_x(const P& p,const P& q){
if(p.x!=q.x)return p.x<q.x;
return p.y<q.y;
}
vector<P> convex_hull(P* ps,int n){
sort(ps,ps+n,cmp_x);
int k=0;
vector<P> qs(n*2);
for(int i=0;i<n;i++){
while((k>1)&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
qs[k++]=ps[i];
}
for(int i=n-2,t=k;i>=0;i--){
while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)k--;
qs[k++]=ps[i];
}qs.resize(k-1);
return qs;
}
double dist(P p,P q){return sqrt((p-q).dot(p-q));}
const int MAX_N=1000;
int N,L;
P ps[MAX_N];
vector<P> con;
void solve(){
for(int i=0;i<N;i++)scanf("%lf%lf",&ps[i].x,&ps[i].y);
con=convex_hull(ps,N);
double res=0;
for(int i=0;i<con.size()-1;i++)res+=dist(con[i],con[i+1]);
res+=dist(con[0],con[con.size()-1]);
res+=2*PI*L;
printf("%d\n",(int)(res+0.5));
}
int main(){
while(~scanf("%d%d",&N,&L))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【凸包周长】
题目: 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 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...
- POJ 1113 Wall 求凸包的两种方法
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31199 Accepted: 10521 Descriptio ...
随机推荐
- BZOJ2097: [Usaco2010 Dec]Exercise 奶牛健美操 贪心+伪树dp+二分
//论全局变量的杀伤力....QAQ#include<cstdio> #include<iostream> #include<cstdlib> #include&l ...
- vector 进阶
http://classfoo.com/ccby/article/jnevK #include <iostream> #include <vector> #include &l ...
- linux 条件判断式
1.利用if ...then if [ 判断条件 ];then 指令 fi 实例一 Y/N: #!/bin/bash #Program: # This program shows "Hell ...
- Codeforces Round #520 (Div. 2) C. Banh-mi
C. Banh-mi time limit per test:1 second memory limit per test:256 megabytes 题目链接:https://codeforc.es ...
- Codeforces Round #478 C. Valhalla Siege
C. Valhalla Siege time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- gogole调试请求体的数据怎么知道
在network---->header->request payload中看 详细情况见下图所示:
- 数据结构之DFS与BFS
深度搜索(DFS) and 广度搜索(BFS) 代码如下: #include "stdafx.h" #include<iostream> #include<st ...
- 图片上传是否为空,以及类型的js验证
function check2() { var file = document.getElementsByName("file").value; if(file=="&q ...
- POJ 1320 Street Numbers 解佩尔方程
传送门 Street Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2529 Accepted: 140 ...
- macos装多个python
简介 Mac包管理工具brew: 安装方法:命令行输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Ho ...