poj1113Wall 求凸包周长 Graham扫描法
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef pair<int ,int > ll;
ll num,dot[1010];
int i;
const double pi=3.1415926535898;
ll operator -(ll a,ll b)
{
return make_pair(a.first-b.first,a.second-b.second);
}
bool cmp(ll a,ll b)
{
return (a.first!=b.first?a.first<b.first:a.second<b.second);
}
int cross(ll a,ll b)
{
return a.first*b.second-b.first*a.second;
}
int d2(ll a,ll b)
{
return (a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second);
}
double d1(ll a,ll b)
{
return sqrt((double)d2(a,b));
}
bool cmp1(ll a,ll b)
{
int r=cross(a-dot[0],b-dot[0]);
return (r!=0?r>0:d2(a,dot[0])<d2(b,dot[0]));
}
void in()
{
cin>>num.first>>num.second;
for(i=0;i<num.first;i++)
cin>>dot[i].first>>dot[i].second;
}
void work()
{
sort(dot,dot+num.first,cmp);
sort(dot,dot+num.first,cmp1); ll box[1010]={dot[0],dot[1]};
int tail=1;
for(i=2;i<num.first;)
{
if(cross(box[tail]-box[tail-1],dot[i]-box[tail-1])>=0)
box[++tail]=dot[i++];
else
tail--;
} double ans=d1(box[0],box[tail])+2*pi*num.second;
for(i=0;i<tail;i++)
ans+=d1(box[i],box[i+1]);
printf("%.0lf\n",ans);
}
int main()
{
in();
work();
}
poj1113Wall 求凸包周长 Graham扫描法的更多相关文章
- POJ 1113 Wall(Graham求凸包周长)
题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- Wall---hdu1348(求凸包周长 模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1348:Wall(计算几何,求凸包周长)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 凸包模板——Graham扫描法
凸包模板--Graham扫描法 First 标签: 数学方法--计算几何 题目:洛谷P2742[模板]二维凸包/[USACO5.1]圈奶牛Fencing the Cows yyb的讲解:https:/ ...
- HDU 1392 Surround the Trees (Graham求凸包周长)
题目链接 题意 : 让你找出最小的凸包周长 . 思路 : 用Graham求出凸包,然后对每条边求长即可. Graham详解 #include <stdio.h> #include < ...
- poj1873(二进制枚举+求凸包周长)
题目链接:https://vjudge.net/problem/POJ-1873 题意:n个点(2<=n<=15),给出n个点的坐标(x,y).价值v.做篱笆时的长度l,求选择哪些点来做篱 ...
随机推荐
- ubantu16.04安装配置samba服务(原创)
1.安装samba服务 $ sudo apt-get install samba samba-common$ sudo apt-get install smbclient 如果你开启了防火墙,关闭: ...
- JS中对数组的操作方法
不断加入中.... 一.数组的增删 1.push():从后面追加 pop():从后面删除一个. 二.数组与字符串的转换 split():用分隔符生成数组 join():将数组用分隔符连为字符串. 三. ...
- HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】
Problem Description Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition ...
- 【分块】bzoj1798 [Ahoi2009]Seq 维护序列seq
分块,打标记,维护两个标记:乘的 和 加的. 每次 区间乘的时候,对 乘标记 和 加标记 都 乘上那个值. 每次 区间加的时候 对 加标记 加上那个值. (ax+b)*v=axv+bv.开 long ...
- 1.7(java学习笔记)package和import
package package主要用于管理类,在java中同一个包下不能有相同的类名,可有时项目总会出现很多同名的类,这时就需要通过包来管理类.不同的包下可以有相同的类名. 包就有点类似于文件夹,不同 ...
- Problem A: 调用函数,求三个数中最大数
#include<stdio.h> int max(int a,int b,int c); int main() { int a,b,c; while(scanf("%d %d ...
- cojs.tk(所有题目来源) 树状数组专练
1.求和问题 ★ 输入文件:sum.in 输出文件:sum.out 简单对比时间限制:1.2 s 内存限制:128 MB [问题描述] 在一个长度为n的整数数列中取出连续的若干 ...
- Jackson错误:Can not deserialize instance of java.lang.String out of START_OBJECT token
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not des ...
- C# 使用 System.Web.Script.Serialization 解析 JSON
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...
- IDEA中添加类的创建者信息
创建方法: 1. 使用快捷键(ctrl + alt + s),在弹出框中左边侧选择 Editor -> File and Code Templates,左边侧相应会更新 右边侧选择 Class, ...