BZOJ1069 [SCOI2007]最大土地面积 【凸包 + 旋转卡壳】
题目链接
题解
首先四个点一定在凸包上
我们枚举对角线,剩下两个点分别是两侧最远的点
可以三分,复杂度\(O(n^2logn)\)
可以借鉴旋转卡壳的思想,那两个点随着对角线的一定单调不减,可以用两个指针维护,复杂度\(O(n^2)\)
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 2005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct point{double x,y;}p[maxn],t[maxn];
inline bool operator <(const point& a,const point& b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
inline point operator +(const point& a,const point& b){
return (point){a.x + b.x,a.y + b.y};
}
inline point operator -(const point& a,const point& b){
return (point){a.x - b.x,a.y - b.y};
}
inline double operator *(const point& a,const point& b){
return a.x * b.x + a.y * b.y;
}
inline double cross(const point& a,const point& b){
return a.x * b.y - a.y * b.x;
}
inline double dis(const point& a,const point& b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
inline double S(const point& a,const point& b,const point& c){
return fabs(0.5 * cross(c - a,c - b));
}
int n,st[maxn],top;
void cal(){
sort(p + 1,p + 1 + n);
st[top = 1] = 1;
for (int i = 2; i <= n; i++){
while (top > 1 && cross(p[i] - p[st[top]],p[st[top]] - p[st[top - 1]]) <= 0)
top--;
st[++top] = i;
}
int tmp = top;
for (int i = n - 1; i; i--){
while (top > tmp && cross(p[i] - p[st[top]],p[st[top]] - p[st[top - 1]]) <= 0)
top--;
st[++top] = i;
}
n = --top;
for (int i = 1; i <= n; i++) t[i] = p[st[i]];
for (int i = 1; i <= n; i++) p[i] = t[i];
}
void solve(){
if (n == 3){printf("%.3lf",S(p[1],p[2],p[3])); return;}
double ans = 0;
for (int i = 1; i <= n - 3; i++){
int x = i + 1,y = i + 3;
for (int j = i + 3; j <= n; j++){
if (S(p[i],p[i + 2],p[j]) > S(p[i],p[i + 2],p[y]))
y = j;
}
ans = max(ans,S(p[i],p[i + 2],p[x]) + S(p[i],p[i + 2],p[y]));
for (int j = i + 3; j <= n; j++){
while (x + 1 < j && S(p[i],p[j],p[x + 1]) > S(p[i],p[j],p[x])) x++;
while (y + 1 <= n && S(p[i],p[j],p[y + 1]) > S(p[i],p[j],p[y])) y++;
ans = max(ans,S(p[i],p[j],p[x]) + S(p[i],p[j],p[y]));
}
}
printf("%.3lf\n",ans);
}
int main(){
n = read();
if (n <= 2) {puts("0"); return 0;}
REP(i,n) scanf("%lf%lf",&p[i].x,&p[i].y);
cal();
//REP(i,n) printf("(%lf,%lf)\n",p[i].x,p[i].y);
solve();
return 0;
}
BZOJ1069 [SCOI2007]最大土地面积 【凸包 + 旋转卡壳】的更多相关文章
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
- [BZOJ1069][SCOI2007]最大土地面积 凸包+旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3669 Solved: 1451[Submit][Sta ...
- luogu P4166 [SCOI2007]最大土地面积 凸包 旋转卡壳
LINK:最大土地面积 容易想到四边形的边在凸包上面 考虑暴力枚举凸包上的四个点计算面积. 不过可以想到可以直接枚举对角线的两个点找到再在两边各找一个点 这样复杂度为\(n^3\) 可以得到50分. ...
- bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳
题目大意: 二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大 题解: 很容易发现这四个点一定在凸包上 所以我们枚举一条边再旋转卡壳确定另外的两个点即可 旋(xuan2)转(zhua ...
- BZOJ1069 SCOI2007 最大土地面积 凸包、旋转卡壳
传送门 在这里假设可以选择两个相同的点吧-- 那么选出来的四个点一定会在凸包上 建立凸包,然后枚举这个四边形的对角线.策略是先枚举对角线上的一个点,然后沿着凸包枚举另一个点.在枚举另一个点的过程中可以 ...
- bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2277 Solved: 853[Submit][Stat ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- [SCOI2007]最大土地面积(旋转卡壳)
首先,最大四边形的四个点一定在凸包上 所以先求凸包 有个结论,若是随机数据,凸包包括的点大约是\(\log_2n\)个 然鹅,此题绝对不会这么轻松,若\(O(n^4)\)枚举,只有50分 所以还是要想 ...
- [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 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
随机推荐
- 开源工具 | 手游自动化框架GAutomator,新增iOS系统和UE4引擎支
WeTest 导读 GAutomator是腾讯WeTest推出的手游自动化测试框架,已用于腾讯多个手游项目组的自动化测试. 1.GAutomator诞生背后 研究过手游自动化测试的同学都知道,虽然市场 ...
- 对posintion属性的简单认识,对于还在纠结的同学们,有一定的帮助
position的四个属性值: relative ,absolute ,fixed,static 下面分别讲述这四个属性,以简单代码表示 <div id="parent" ...
- Unity 编辑器扩展 Chapter2—Gizmos
二. 使用Gizoms绘制网格及矩阵转换使用 1. 创建Leve类,作为场景控制类: using UnityEngine; //使用namespace方便脚本管理 namespace RunAndJu ...
- 《Node.js核心技术教程》学习笔记
<Node.js核心技术教程>TOC \o "1-3" \h \z \u 1.章模块化编程 2019.2.19 13:30' PAGEREF _101 \h 1 08D ...
- 240. 搜索二维矩阵 II
二维数组搜索 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target.该矩阵具有以下特性: 每行的元素从左到右升序排列. 每列的元素从上到下升序排列. 示例: 现有矩阵 ...
- 观察者模式——Java实例
一.定义 观察者模式(有时又被称为模型-视图(View)模式.源-收听者(Listener)模式或从属者模式)是软件设计模式的一种.观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个 ...
- 初创型公司如何经济有效的申请邓白氏编码(DUNS)
听说有免费,和800元,1500元,上万元等不同的申请方式?听说申请完还要等十数个工作日让邓白氏和苹果的数据库同步.不同高低价格的申请方式得到的编码都能被苹果接受吗? http://www.zhihu ...
- 如何把node更新到最新的稳定版本
先装n,再用n把node升级到最新稳定版 $ npm install -g n $ n stable
- JS数据结构学习之排序
在看<>这本书中关于排序这一章的时候,我试着用javascript语言来重写里面几个经典的排序方法,包括冒泡排序.快速排序.选择排序.插入排序还有希尔排序. 一.冒泡排序 冒泡排序算是排序 ...
- 第17次Scrum会议(10/29)【欢迎来怼】
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/29 17:20~17:42,总计22min.地点:东北师 ...