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. OSI层次关系

    一.OSI参考模型         今天我们先学习一下以太网最基本也是重要的知识——OSI参考模型. 1.OSI的来源         OSI(Open System Interconnect),即开 ...

  2. linux实时系统监控工具mpstat

    mpstat (RHEL5默认不安装) mpstat是MultiProcessor Statistics的缩写,是实时系统监控工具.其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件 ...

  3. Leetcode24.Swap Nodes in Pairs两两交换链表中的节点

    给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 示例: 给定 1->2->3->4, 你应该返回 2->1->4->3. 说明: 你的算法只能使用常数的 ...

  4. Oracle启动和禁用约束及删除违反约束的记录

    一.禁用约束 alter table table_name disable novalidate constraint constraint_name 二.批量导入数据 三.在开启约束之前一定要检查违 ...

  5. pip list报错:DEPRECATION: The default format will switch to columns in the future.

    一.现象: pip list 显示出以下错误:     DEPRECATION: The default format will switch to columns in the future. Yo ...

  6. 【Codeforces Round #430 (Div. 2) D】Vitya and Strange Lesson

    [链接]点击打开链接 [题意] 给出一个数组,每次操作将整个数组亦或一个数x,问得到的数组的结果中的mex.mex表示为自然数中第一个没有出现过的数. [题解] 异或的效果是可以累加的,所以不用每次都 ...

  7. cf round 482D Kuro and GCD and XOR and SUM

    题意: 开始有个空集合,现在有两种操作: $(1,x)$:给集合加一个数$x$,$x \leq 10^5$; $(2,x,k,s)$:在集合中找一个$a$,满足$a \leq s-x$,而且$k|gc ...

  8. vue使用填坑之:model和v-model的区别

    v-model通常用于input的双向数据绑定 <input v-model="parentMsg">,也可以实现子组件到父组件数据的双向数据绑定:首先说说v-mode ...

  9. 第一周<单元一聚类>

    K-means 聚类算法 初始随机选择 而后不断更新 kmeans 应用 省份归类 调用kmeans方法所需要的参数 n_clusters 指定的聚类中心 init 初始聚类中心的初始化方法 默认k- ...

  10. python 对位运算