Problem - 3934

  晚上为了演示给师弟看水平序的凸包是多么的好写,于是就随便找了一题凸包,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 (凸包+旋转卡壳)的更多相关文章

  1. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  2. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  3. Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)

    题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...

  4. poj 2079 Triangle (二维凸包旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000KB   64bit IO Format: %I64d & %I64u Submit Stat ...

  5. poj 2187 Beauty Contest(二维凸包旋转卡壳)

    D - Beauty Contest Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  6. POJ 2187 凸包+旋转卡壳

    思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说   凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...

  7. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

    链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  8. hdu 3934 Summer holiday(凸包最大内接三角形)

    求n个点能组成的最大三角形,一发旋转卡壳模板题... #include<algorithm> #include<iostream> #include<cstring> ...

  9. HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)

    题目链接   题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...

  10. hdu 最大三角形(凸包+旋转卡壳)

    老师在计算几何这门课上给Eddy布置了一道题目,题目是这样的:给定二维的平面上n个不同的点,要求在这些点里寻找三个点,使他们构成的三角形拥有的面积最大.Eddy对这道题目百思不得其解,想不通用什么方法 ...

随机推荐

  1. GIT → 03:Git的下载和安装

    3.1 Git 下载 官网:https://git-scm.com/ 软件下载地址:https://git-scm.com/downloads 根据自己电脑版本下载对应版本: 3.2 Git 安装 3 ...

  2. html转换成pdf

    指定html转换成pdf 安装插件: npm install --save html2canvas npm install jspdf --save 引入 plugins/ htmlToPdf.js ...

  3. 【CodeVS】1978 Fibonacci数列3

    1978 Fibonacci数列 3 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze 题目描述 Description 斐波纳契数列是这样的数列: f1 = 1 f ...

  4. 【python之路13】python的深浅拷贝

    深浅拷贝 一.数字和字符串 对于 数字 和 字符串 而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 impor ...

  5. ACdream 1099求第k大

    题目链接 瑶瑶的第K大 Time Limit: 10000/5000MS (Java/Others)Memory Limit: 512000/256000KB (Java/Others) Submit ...

  6. Hdu 1299

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  7. LintCode刷题笔记-- InterLeaving

    标签: 动态规划 解题思路 1. 这道题最重要的是,存在三个字符串,但是并不需要两个二维矩阵来进行解,因为可以使用i+j-1来代表s3的下标,这样就可以通过i和j来遍历s3了.因为对于任何一个合法的交 ...

  8. OpenLayers图层

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  9. CentOS7安装步骤

    CentOS7安装详解   本文基于vmware workstations进行CentOS7安装过程展示,关于vmware workstations安装配置本人这里不再介绍,基本过程相当于window ...

  10. 用Direct2D和DWM来做简单的动画效果2

    原文:用Direct2D和DWM来做简单的动画效果2 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sunnyloves/article/detai ...