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 ...
随机推荐
- Mysql无法创建函数解决办法
执行: set global log_bin_trust_function_creators =1; 原文参照:http://www.cnblogs.com/xd502djj/archive/2012 ...
- 洛谷 P2051 [AHOI2009]中国象棋
题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法.大家肯定很清楚,在中国象棋中炮的行走方式是 ...
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之游戏效果预览(一)
今天看完了李刚老师的<疯狂Android讲义>一书中的第18章<疯狂连连看>,从而学会了如何编写一个简单的Android疯狂连连看游戏. 开发这个流行的小游戏,难度适中,而且能 ...
- 16.Django提交表单
Django表单提交一共有三种方式: 1.不使用Django组件进行提交 2.使用django.forms.Form(所有表单类的父类)进行提交 3.使用django.forms.ModelForm( ...
- js基础--substr()和substring()的区别
最近做项目的时候,字符串截取一直用的是substr()方法,有时候需要截取的内容是中间部分的话就很麻烦,需要分两次,第一次截取前半部分,第二次在第一次的基础上截取后半部分.写了几次之后总觉得没对,应该 ...
- python3里面的图片处理库 pillow
在python2下用pil,而在python3下可以安装pillow 功能,在图片上加上几个字 #coding: utf-8 myPath = "./" fontPath = &q ...
- 中国移动OnetNet云平台 使用WIFI模块ESP8266 TCP透传模式传输数据流步骤
测试使用工具: WIFI模块型号:ESP8266 https://item.taobao.com/item.htm?spm=a1z10.1-c.w137712-175513579.2.btbD9X&a ...
- Data Structure Binary Tree: Boundary Traversal of binary tree
http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/ #include <iostream> #include & ...
- [原创]关于设置linux中vim 显示行号
1.更改所有账户配置 直接更改/etc/vimrc vim /etc/vimrc 在vimrc文件的最后添加 set nu 即可 wq退出. 这样,不论使用哪个账号登陆,vim打开后都显示行号 2.为 ...
- 【leetcode刷题笔记】Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...