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. 基于LSTM对西储大学轴承故障进行分析

    这篇文章是小萌新对西储大学轴承故障进行分析,固定特征为故障直径为0.007,电机转速为1797,12k驱动端故障数据(Drive_End)即DE-time.故障类型y值:滚动体故障,内圈故障,3时,6 ...

  2. 从Java到C++——union的使用方法

    版权声明:本文为博主原创文章,未经博主同意不得用于不论什么商业用途,转载请注明出处. https://blog.csdn.net/luoweifu/article/details/33342965 你 ...

  3. Ocelot(二)- 请求聚合

    原文:Ocelot(二)- 请求聚合 Ocelot(二)- 请求聚合与负载均衡 作者:markjiang7m2 原文地址:https://www.cnblogs.com/markjiang7m2/p/ ...

  4. 创建动态MSSQL数据库表的方法

    代码如下: ImportsSystem.Data ImportsSystem.Data.SqlClient PublicClassForm1 InheritsSystem.windows.Forms. ...

  5. ML面试1000题系列(71-80)

    本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 71.看你是搞视觉的,熟悉哪些CV框架,顺带聊聊 ...

  6. Vue调试神器之Vue.js devTools

    Vue项目中使用Vue.js devTools这款调试神器,可以极大程度的提高我们的开发效率. 安装 1.打开Chrome网上应用商店安装插件(自墙),直接搜索devTools安装即可.贵宾传送阵,请 ...

  7. elastic search book [ ElasticSearch book es book]

    谁在使用ELK 维基百科, github都使用 ELK (ElasticSearch es book) ElasticSearch入门 Elasticsearch入门,这一篇就够了==>http ...

  8. poj3422 最小费用流

    一遍的话秩序要dp就好,但是这里要删去点.此题可以转化为最小费用流.开始我想了半天纠结怎么处理到过一次后值变0,看了书之后发现拆点解决了这个问题. 对于点t,拆为t-->t',容量为1,费用为负 ...

  9. SDUT-3373_数据结构实验之查找一:二叉排序树

    数据结构实验之查找一:二叉排序树 Time Limit: 400 ms Memory Limit: 65536 KiB Problem Description 对应给定的一个序列可以唯一确定一棵二叉排 ...

  10. 封装好的PDO类

    封装PDO类,方便使用: <?php header('content-type:text/html;charset=utf-8'); /** * 封装PDODB类 */ // 加载接口 // i ...