LightOJ 1239 - Convex Fence 凸包周长
题意:类似POJ的宫殿围墙那道,只不过这道题数据稍微强了一点,有共线的情况
思路:求凸包周长加一个圆周长
/** @Date : 2017-07-20 15:46:44
* @FileName: LightOJ 1239 求凸包.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const double Pi = acos(-1.0);
struct point
{
double x, y;
point(){}
point(double _x, double _y){x = _x, y = _y;}
point operator -(const point &b) const
{
return point(x - b.x, y - b.y);
}
double operator *(const point &b) const
{
return x * b.x + y * b.y;
}
double operator ^(const point &b) const
{
return x * b.y - y * b.x;
}
}; double xmult(point p1, point p2, point p0)
{
return (p1 - p0) ^ (p2 - p0);
} double distc(point a, point b)
{
return sqrt((double)((b - a) * (b - a)));
}
int sign(double x)
{
if(fabs(x) < eps)
return 0;
if(x < 0)
return -1;
else
return 1;
} ////////
int n;
point stk[N];
point p[N]; int cmpC(point a, point b)//水平序排序
{
return sign(a.x - b.x) < 0 || (sign(a.x - b.x) == 0 && sign(a.y - b.y) < 0);
} int Graham(point *p, int n)//水平序
{
sort(p, p + n, cmpC);
int top = 0;
for(int i = 0; i < n; i++)
{
while(top >= 2 && sign(xmult(stk[top - 2], stk[top - 1], p[i])) < 0)
top--;
stk[top++] = p[i];
}
int tmp = top;
for(int i = n - 2; i >= 0; i--)
{
while(top > tmp && sign(xmult(stk[top - 2],stk[top - 1] ,p[i] )) < 0)
top--;
stk[top++] = p[i];
}
if(n > 1)
top--;
return top;
} int main()
{
int T;
cin >> T;
int c = 0;
while(T--)
{
int n;
double l;
cin >> n >> l;
double x, y;
for(int i = 0; i < n; i++)
{
scanf("%lf%lf", &x, &y);
p[i] = point(x, y);
}
int m = Graham(p, n);
double ans = 2 * Pi * l;
stk[m++] = stk[0];//注意只有直线的情况
for(int i = 0; i < m - 1; i++)
ans += distc(stk[i], stk[i + 1]);
printf("Case %d: %.10lf\n", ++c, ans);
}
return 0;
}
LightOJ 1239 - Convex Fence 凸包周长的更多相关文章
- Convex Fence
Convex Fence I have a land consisting of n trees. Since the trees are favorites to cows, I have a bi ...
- 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 ...
- POJ 1113 Wall(Graham求凸包周长)
题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...
- HDU 1392 Surround the Trees (Graham求凸包周长)
题目链接 题意 : 让你找出最小的凸包周长 . 思路 : 用Graham求出凸包,然后对每条边求长即可. Graham详解 #include <stdio.h> #include < ...
- poj 1113 凸包周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33888 Accepted: 11544 Descriptio ...
- leetcode 587. Erect the Fence 凸包的计算
leetcode.587.Erect the Fence 凸包问题.好像是我在leetcode做的第一个凸包问题吧. 第一次做,涉及到的东西还是蛮多的.有一个东西很重要,就是已知一个点和一个矢量,求这 ...
- hdu 1392:Surround the Trees(计算几何,求凸包周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- nginx配置,php安装
yum -y install libxml2 libxml2-develyum -y install libxslt-devel yum -y install bzip2-devel yum -y i ...
- winform界面之固定大小随dpi
场景: 已经更改成大小可随dpi改变,可是在用applyresoures()之后(添加更改语言功能),发现控件大小失真. 分析:applyresoures()是把该控件的属性改为程序设计的固定大小,不 ...
- IT小小鸟 读书笔记
讲真的,整本书我并没有看完,翻阅了一下,然后小小的借鉴了一下! 首先设计你自己的进度条 进度条的设计是一个很多人都知道的故事:同样的耗时,如果不给任何进度提示,只是在完成之后才弹出一个完成消息,中间没 ...
- DescriptionAttribute Class
指定属性或事件的描述. [Description("The image associated with the control"),Category("Appearanc ...
- MUI设置卡头卡位的形式进行切换
这是mui的官方帮助文档,一切问题都能在这里找到http://dev.dcloud.net.cn/mui/ui/解决方案. 下面是MUI官方对卡头卡尾的一些描述: 在mobile app开发过程中,经 ...
- lintcode-425-电话号码的字母组合
425-电话号码的字母组合 Given a digit string excluded 01, return all possible letter combinations that the num ...
- inux下mysql的root密码忘记解决方法
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...
- 还原 listagg/wm_concat 后的数据 pack_split_listatt ;
1.创建表并制作测试数据: --创建测试表 : CREATE TABLE split_table ( NAME ), ID ) ); --准备测试数据 : INSERT INTO split_tabl ...
- 关于ADO一个容易被忽视的问题!UpdateBatch [问题点数:0分]
这是一个常见但容易被忽视的问题,旧贴有问及但没答案,因此提高分数.相信大家常这样使用Cache模式:ADOConnection1.BeginTrans;Try ADODataSet1.UpdateBa ...
- 【数据库】SQL分组多列统计(GROUP BY后按条件分列统计)
select whbmbh ,zt,1 as tjsl from fyxx group by zt,whbmbh select whbmbh,sum(case zt when '有效' then 1 ...