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 ...
随机推荐
- DP---(POJ1159 POJ1458 POJ1141)
POJ1159,动态规划经典题目,很适合初学者入门练手. 求:为了使字符串左右对称,应该插入的最小字符数目. 设字符串为S1 S2 S3 - Sn. 这个字符串有n个字符,根据DP的基本思路,减少问题 ...
- MySQL 忘记root密码怎么办
前言:记住如果忘记root密码,在启动MySQL的时候,跳过查询授权表就ok了. 对于RedHat 6 而言 (1)启动mysqld 进程时,为其使用:--skip-grant-tables --sk ...
- form表单元素中disabled的元素的值不会提交到服务器
1.表单元素中disabled的元素的值不会提交到服务器,后台获取的值为null <form id="myForm" action="#" method= ...
- Mybatis 映射关系
相比 Hibernate,Mybatis 的映射关系就显得简单了很多. 未完待续....
- android studio 运行太慢了
Android Studio每次升级/安装 Android Studio 之后最好都修改一下这个参数:到 Android Studio 安装目录,找到 bin/studio(64?).vmoption ...
- python的N个小功能(更新文件)
########################################################################## #对于第二份文件:第一份与第二份不相同,以第二份为 ...
- poj2914-Minimum Cut
题意 \(n\) 个点 \(m\) 条边的无向带权图求全局最小割.\(n\le 500,m\le \frac{n(n-1)}{2}\) . 分析 参考了 这篇博客,去给他点赞. 嘛,今天研究了一下全局 ...
- 【bzoj5130】[Lydsy12月赛]字符串的周期 DFS+KMP
题目描述 给定 $n$ 和 $m$ ,求所有 长度为 $n$ ,字符集大小为 $m$ 的字符串,每个前缀的最短循环节长度乘积 的总和. $n\le 12,m\le 10^9$ 题解 DFS+KMP 对 ...
- 【转载】Java中的锁机制 synchronized & 偏向锁 & 轻量级锁 & 重量级锁 & 各自优缺点及场景 & AtomicReference
参考文章: http://blog.csdn.net/chen77716/article/details/6618779 目前在Java中存在两种锁机制:synchronized和Lock,Lock接 ...
- AngularJS中$watch
$watch在digest执行时,如果watch观察的value与上一次执行时不一样时,就会被触发.angularjs内部的watch实现了页面随model的及时更新.$watch 方法在用的时候主要 ...