hdu 3934 Summer holiday (凸包+旋转卡壳)
晚上为了演示给师弟看水平序的凸包是多么的好写,于是就随便找了一题凸包,25min居然1y掉了。。
代码如下:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
const double EPS = 1e-;
inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator - (Point a) { return Point(x - a.x, y - a.y);}
bool operator < (Point a) const { return sgn(x - a.x) < || sgn(x - a.x) == && y < a.y;}
} ; inline double cross(Point a, Point b) { return a.x * b.y - a.y * b.x;} int andrew(Point *pt, Point *ch, int n) {
sort(pt, pt + n);
int m = ;
for (int i = ; i < n; i++) {
while (m > && sgn(cross(pt[i] - ch[m - ], ch[m - ] - ch[m - ])) <= ) m--;
ch[m++] = pt[i];
}
int k = m;
for (int i = n - ; i >= ; i--) {
while (m > k && sgn(cross(pt[i] - ch[m - ], ch[m - ] - ch[m - ])) <= ) m--;
ch[m++] = pt[i];
}
if (n > ) m--;
return m;
} Point ch[N], pt[N];
inline double area(Point a, Point b, Point c) { return fabs(cross(c - a, b - a));} double work(Point *pt, int n) {
if (n < ) return ;
double ans = area(pt[], pt[], pt[]);
for (int i = , j = , k = ; i < n; i++) {
while (true) {
bool df = false;
if (i == j) j = (j + ) % n;
if (j == k) k = (k + ) % n;
while (true) {
double a1 = area(pt[i], pt[j], pt[k]);
double a2 = area(pt[i], pt[j], pt[(k + ) % n]);
ans = max(ans, a1);
if (sgn(a1 - a2) > ) break;
k = (k + ) % n;
df = true;
}
while (true) {
double a1 = area(pt[i], pt[j], pt[k]);
double a2 = area(pt[i], pt[(j + ) % n], pt[k % n]);
ans = max(ans, a1);
if (sgn(a1 - a2) > ) break;
j = (j + ) % n;
df = true;
}
if (!df) break;
}
}
return ans / ;
} int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = ; i < n; i++) scanf("%lf%lf", &pt[i].x, &pt[i].y);
n = andrew(pt, ch, n);
printf("%.2f\n", work(ch, n));
}
return ;
}
——written by Lyon
hdu 3934 Summer holiday (凸包+旋转卡壳)的更多相关文章
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
- UVA 4728 Squares(凸包+旋转卡壳)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
- Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)
题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...
- poj 2079 Triangle (二维凸包旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Stat ...
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2187 凸包+旋转卡壳
思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说 凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- hdu 3934 Summer holiday(凸包最大内接三角形)
求n个点能组成的最大三角形,一发旋转卡壳模板题... #include<algorithm> #include<iostream> #include<cstring> ...
- HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)
题目链接 题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...
- hdu 最大三角形(凸包+旋转卡壳)
老师在计算几何这门课上给Eddy布置了一道题目,题目是这样的:给定二维的平面上n个不同的点,要求在这些点里寻找三个点,使他们构成的三角形拥有的面积最大.Eddy对这道题目百思不得其解,想不通用什么方法 ...
随机推荐
- Python服务端工程师就业面试指导
Python服务端工程师就业面试指导 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大家看的时候 ...
- java图形验证码生成工具类及web页面校验验证码
最近做验证码,参考网上案例,发现有不少问题,特意进行了修改和完善. 验证码生成器: import javax.imageio.ImageIO; import java.awt.*; import ja ...
- spring boot定时任务解析
在SpringBoot中定时任务一般使用的是@Scheduled注解. @Scheduled 1.注解内容: @Target({ElementType.METHOD, ElementType.ANNO ...
- linux挂载点 和 文件系统$ mount$ cat /etc/fstab$ vgs$ pvs$ lvs$ df -h$ lsof +D / /* beware not to kill your box */
$ mount$ cat /etc/fstab$ vgs$ pvs$ lvs$ df -h$ lsof +D / /* beware not to kill your box */ 一共挂载了多少文件 ...
- HDU 4280 Island Transport(dinic+当前弧优化)
Island Transport Description In the vast waters far far away, there are many islands. People are liv ...
- 洛谷P2835 刻录光盘 [2017年6月计划 强连通分量02]
P2835 刻录光盘 题目描述 在JSOI2005夏令营快要结束的时候,很多营员提出来要把整个夏令营期间的资料刻录成一张光盘给大家,以便大家回去后继续学习.组委会觉得这个主意不错!可是组委会一时没有足 ...
- expect.js
前言 1> 借鉴里面的应用思想,使用断言提高代码的健壮性及维护性 2> 实现方式--不采用直接嵌入expect的方式,统一进行重写(提取常用断言方法,重新构造API) 官网介绍 https ...
- 将jacoco集成到测试工具平台
最近在做接口测试,想通过代码覆盖率来判断一下接口用例是否缺失,但是每次通过命令来生成覆盖率报告,感觉太麻烦,所以就想着把jacoco集成到测试工具平台中,只需要点几个按钮,就能查看到覆盖率报告. 测试 ...
- 【JZOJ3297】【SDOI2013】逃考(escape)
Mission 高考又来了,对于不认真读书的来讲真不是个好消息.为了小杨能在家里认真读书,他的亲戚决定驻扎在他的家里监督他学习,有爷爷奶奶.外公外婆.大舅.大嫂.阿姨-- 小杨实在是忍无可忍了,这种生 ...
- IDEA 创建文件夹总默认根节点问题解决
上面是文件夹结构显示,如果勾掉,就是按层级显示,空目录不会自动折叠成一行 原文地址;https://blog.csdn.net/huangjunwei6/article/details/7150755 ...