bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳
题目大意:
二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大
题解:
很容易发现这四个点一定在凸包上
所以我们枚举一条边再旋转卡壳确定另外的两个点即可
旋(xuan2)转(zhuan4)卡(qia3)壳(ke2)
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 2048;
const double eps = 1e-9;
inline int dcmp(double x){
if(x < eps && x > -eps) return 0;
return x > 0 ? 1 : -1;
}
struct Point{
double x,y;
Point(double a = .0,double b = .0){
x=a;y=b;
}
};
typedef Point Vector;
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x + b.x,a.y + b.y);
}
Vector operator - (const Vector &a,const Vector &b){
return Vector(a.x - b.x,a.y - b.y);
}
double operator * (const Vector &a,const Vector &b){
return a.x*b.x + a.y*b.y;
}
double operator ^ (const Vector &a,const Vector &b){
return a.x*b.y - a.y*b.x;
}
double trigonArea(const Point &a,const Point &b,const Point &c){
return abs((b - a)^(c - a))/2.0;
}
inline bool cmp(const Point &a,const Point &b){
return dcmp(a.x - b.x) == 0 ? a.y < b.y : a.x < b.x;
}
Point p[maxn],ch[maxn];
int m = 0,n;
void convex(){
sort(p+1,p+n+1,cmp);m = 0;
for(int i=1;i<=n;++i){
while(m > 1 && dcmp((ch[m] - ch[m-1])^(p[i] - ch[m])) <= 0) -- m;
ch[++m] = p[i];
}int k = m;
//printf("%d\n",k);
for(int i=n-1;i>=1;--i){
while(m > k && dcmp((ch[m] - ch[m-1])^(p[i] - ch[m])) <= 0) -- m;
ch[++m] = p[i];
}if(n > 1) -- m;
//printf("%d\n",m);
swap(n,m);swap(p,ch);
}
#define nx(x) ((x) % n + 1)
double spinClipShell(){
double ret = .0;p[n+1] = p[1];
for(int i=1;i<=n;++i){
int x = nx(i);
int y = nx(i+2);
for(int j=i+2;j<=n;++j){
while((nx(x) != j) && dcmp(trigonArea(p[x],p[i],p[j]) - trigonArea(p[x+1],p[i],p[j])) < 0) x = nx(x);
while((nx(y) != i) && dcmp(trigonArea(p[y],p[i],p[j]) - trigonArea(p[y+1],p[i],p[j])) < 0) y = nx(y);
ret = max(ret,trigonArea(p[x],p[i],p[j]) + trigonArea(p[y],p[i],p[j]));
}
}return ret;
}
int main(){
read(n);
for(int i=1;i<=n;++i) scanf("%lf%lf",&p[i].x,&p[i].y);
convex();printf("%.3lf\n",spinClipShell());
getchar();getchar();
return 0;
}
bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳的更多相关文章
- bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2277 Solved: 853[Submit][Stat ...
- [BZOJ1069][SCOI2007]最大土地面积 凸包+旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3669 Solved: 1451[Submit][Sta ...
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
- luogu P4166 [SCOI2007]最大土地面积 凸包 旋转卡壳
LINK:最大土地面积 容易想到四边形的边在凸包上面 考虑暴力枚举凸包上的四个点计算面积. 不过可以想到可以直接枚举对角线的两个点找到再在两边各找一个点 这样复杂度为\(n^3\) 可以得到50分. ...
- BZOJ 1069: [SCOI2007]最大土地面积(旋转卡壳)
题目链接~ 1069: [SCOI2007]最大土地面积 思路很简单,极角排序求完凸包后,在凸包上枚举对角线,然后两边分别来两个点旋转卡壳一下,搞定! 不过计算几何的题目就是这样,程序中间的处理还是比 ...
- BZOJ 1069: [SCOI2007]最大土地面积 [旋转卡壳]
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2978 Solved: 1173[Submit][Sta ...
- bzoj 1069 [SCOI2007]最大土地面积——旋转卡壳
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1069 发现 n 可以 n^2 .所以枚举对角线,分开的两部分三角形就可以旋转卡壳了. 注意坐 ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- ●BZOJ 1069 [SCOI2007]最大土地面积
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1069 题解: 计算几何,凸包,旋转卡壳 其实和这个题差不多,POJ 2079 Triangl ...
随机推荐
- EasyDSS视频点播服务器实现多分辨率/多码率无缝切换的办法
EasyDSS流媒体音视频直播与点播服务器软件,是一套提供一站式的转码.点播.直播.检索.回放.录像下载服务的高性能RTMP/HLS/HTTP-FLV流媒体服务,极大地简化了流媒体相关业务的开发和集成 ...
- POJ 2031 Building a Space Station【经典最小生成树】
链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- HTML元素嵌套关系
- Go 学习笔记
官网: https://golang.org/ 环境: $GOROOT: GOROOT环境变量指定了Go的安装目录. $GOPATH: GOPATH 环境变量指定workspace的目录. 命令行: ...
- Java基础 - 常量与变量
A:常量 内存中的一小块区域,在程序执行过程中,其值不可以发生改变的量称为常量 常量的几种表现形式: a:字符串常量 "HelloWorld" b:整数常量 12 c:小数常量 1 ...
- sql语句 字段的赋值
将同一个表中的一个字段2的所有值赋值给另一个字段1 UPDATE 表名 SET 字段1 = 字段2 也可以把字段所有的值赋为null UPDATE 表名 SET 字段1 = null
- ubuntu14.04 pygame安装 python2.7
系统:ubuntu14.04 LTS amd64python版本:2.7.6pygame版本:1.9.1release别这种方法了,这么安装不知道什么原因就出现了问题,在使用pygame.image. ...
- 《程序员代码面试指南》第一章 栈和队列 构造数组的MaxTree
题目 给出一个无重复元素的数组,构造此数组的MaxTree, java代码 /** * @Description: 构造数组的MaxTree * @Author: lizhouwei * @Creat ...
- 【Flask】模板继承
# 模版继承笔记: ### 为什么需要模版继承:模版继承可以把一些公用的代码单独抽取出来放到一个父模板中.以后子模板直接继承就可以使用了.这样可以重复性的代码,并且以后修改起来也比较方便. ### 模 ...
- Android系统篇之—-编写系统服务并且将其编译到系统源码中【转】
本文转载自:http://www.wjdiankong.cn/android%E7%B3%BB%E7%BB%9F%E7%AF%87%E4%B9%8B-%E7%BC%96%E5%86%99%E7%B3% ...