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对这道题目百思不得其解,想不通用什么方法 ...
随机推荐
- 避免SQL注入三慷慨法
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wangyy130/article/details/26154837 要说SQL注入还要从 ...
- go语言:类型转换
类型转换用于将一种类型的变量转换为另一种类型的变量. 有以下场景: package main import "fmt" func main() { var sum int = 17 ...
- php 获取一张图片所有点的颜色值
image_all_rgb.php <?php //similar_text($numStr, $val, $pre); //计算两个字符串的相似度 //print_r($pre); $imgP ...
- new 在C++ 中的用法
我对C++一无所知 看参考手册 来看一下参考手册,总共有三种用法 下面是网站上给出的例子 // operator new example #include <iostream> // st ...
- vue和element全局loading
http请求的代码如下: import axios from 'axios' import { Message} from 'element-ui' import store from '../sto ...
- 【笔记】LR录制方式和常用函数
本文为本人复习LR时,笔记整理.以备后续查阅. 注意:录制脚本时,选择不同的协议下录制时设置选项也是不相同的,我们这里介绍的是基于协议web(http/html)录制选项设置. 对于web(http/ ...
- 【JZOJ3299】【SDOI2013】保护出题人 三分+凸壳
题面 出题人铭铭认为给SDOI2012 出题太可怕了,因为总要被骂,于是他又给SDOI2013 出题了. 参加SDOI2012 的小朋友们释放出大量的僵尸,企图攻击铭铭的家.而你作为SDOI2013 ...
- JetBrains 系列软件--操作数据库+centos系统
这系列软件贼强大! 能操作数据库 也能操作centos(linux)系统 由于这系列都有这两个功能,下面以最近常用的JetBrains PhpStorm 2017.2.1 x64来举例子: 一.操作数 ...
- 自定义View系列教程01--常用工具介绍
站在源码的肩膀上全解Scroller工作机制 Android多分辨率适配框架(1)- 核心基础 Android多分辨率适配框架(2)- 原理剖析 Android多分辨率适配框架(3)- 使用指南 自定 ...
- python中的输入和输出
输入和输出 输出: 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print('hello, ...