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 ...
随机推荐
- Tomcat的目录结构(tomcat 7)
/bin 存放在Windows平台以及Linux平台上启动和关闭Tomat的脚本文件 /conf 存放关于Tomcat服务器的全局配置. /li ...
- GET,POST
HTTPHTTP(即超文本传输协议)是现代网络中最常见和常用的协议之一,设计它的目的是保证客户机和服务器之间的通信.HTTP 的工作方式是客户端与服务器之间的 “请求-响应” 协议.客户端可以是 We ...
- eclipse 创建maven web 项目
虽然网上教程一大把,但也重新整理下. 一.创建项目 1.Eclipse中用Maven创建项目 上图中Next 2.继续Next 3.选maven-archetype-webapp后,next 4.填写 ...
- An Ordinary Game(简单推导)
An Ordinary Game Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement There ...
- 【python】-- 类的多继承、经典类、新式类
继承知识点补充 在python还支持多继承,但是一般我们很少用,有些语言干脆就不支持多继承,有多继承,就会带来两个概念,经典类和新式类. 一.多继承 之前我们都是讲的单继承,那么什么是多继承呢?说白了 ...
- 在VS2017环境中编译libxml2库
libxml2库编译 1.下载libxml2,官网是:http://www.xmlsoft.org/downloads.html, 我下载的版本是:libxml2-sources-2.9.7.tar. ...
- ElasticSearch(二十四)基于scoll技术滚动搜索大量数据
1.为什么要使用scroll? 如果一次性要查出来比如10万条数据,那么性能会很差,此时一般会采取用scoll滚动查询,一批一批的查,直到所有数据都查询完处理完 2.原理 使用scoll滚动搜索,可以 ...
- go语言之接口一
在Go语言中,一个类只需要实现了接口要求的所有函数,我们就说这个类实现了该接口 我们定义了一个File类,并实现有Read().Write().Seek().Close()等方法.设 想我们有如下接口 ...
- 如何让Jackson JSON生成的数据包含的中文以unicode方式编码
我们都知道,Jackson JSON以高速.方便和灵活著称.之前的文章中介绍过使用注解的形式来规定如何将一个对象序列化成JSON的方法,以及如何将一个JSON数据反序列化到一个对象上.但是美中不足的一 ...
- [原创]java WEB学习笔记36:Java Bean 概述,及在JSP 中的使用,原理
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...