BZOJ1069 SCOI2007 最大土地面积 凸包、旋转卡壳
在这里假设可以选择两个相同的点吧……
那么选出来的四个点一定会在凸包上
建立凸包,然后枚举这个四边形的对角线。策略是先枚举对角线上的一个点,然后沿着凸包枚举另一个点。在枚举另一个点的过程中可以使用旋转卡壳找到在对角线两侧、距离对角线最远的两个点,这样的四个点就可以贡献答案。总时间复杂度\(O(n^2)\)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<vector>
#include<cmath>
//This code is written by Itst
using namespace std;
#define ld long double
#define eps 1e-9
#define nxt(x) ((x) % cnt + 1)
bool cmp(ld a , ld b){
return a + eps > b && a - eps < b;
}
struct comp{
ld x , y;
comp(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
comp operator -(comp a){
return comp(x - a.x , y - a.y);
}
bool operator <(const comp a)const{
return x < a.x || cmp(x , a.x) && y < a.y;
}
}now[2010];
int st[2010] , ind[2010];
int top , N , cnt;
inline ld dot(comp a , comp b){
return a.x * b.y - a.y * b.x;
}
inline ld calcS(comp a , comp b , comp c){
return fabs(dot(b - a , c - a)) / 2;
}
void init(){
for(int i = 1 ; i <= N ; ++i){
while(top >= 2 && dot(now[i] - now[st[top]] , now[st[top]] - now[st[top - 1]]) > -eps)
--top;
st[++top] = i;
}
for(int i = 1 ; i <= top ; ++i)
ind[++cnt] = st[i];
top = 0;
for(int i = N ; i ; --i){
while(top >= 2 && dot(now[i] - now[st[top]] , now[st[top]] - now[st[top - 1]]) > -eps)
--top;
st[++top] = i;
}
for(int i = 2 ; i < top ; ++i)
ind[++cnt] = st[i];
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif
scanf("%d" , &N);
for(int i = 1 ; i <= N ; ++i)
scanf("%Lf %Lf" , &now[i].x , &now[i].y);
sort(now + 1 , now + N + 1);
init();
if(cnt == 3)
cout << fixed << setprecision(3) << calcS(now[st[1]] , now[st[2]] , now[st[3]]);
else{
ld ans = 0;
for(int i = 1 ; i <= cnt ; ++i){
int p = i , q = nxt(nxt(i));
for(int j = nxt(nxt(i)) ; nxt(j) != i ; j = nxt(j)){
while(calcS(now[ind[p]] , now[ind[i]] , now[ind[j]]) < calcS(now[ind[nxt(p)]] , now[ind[i]] , now[ind[j]]))
p = nxt(p);
while(calcS(now[ind[q]] , now[ind[i]] , now[ind[j]]) < calcS(now[ind[nxt(q)]] , now[ind[i]] , now[ind[j]]))
q = nxt(q);
ans = max(ans , calcS(now[ind[p]] , now[ind[i]] , now[ind[j]]) + calcS(now[ind[q]] , now[ind[i]] , now[ind[j]]));
}
}
cout << fixed << setprecision(3) << ans;
}
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 ...
- 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 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
随机推荐
- windows平台vs2010编译64位libiconv与libxml2
(一)安装libiconv下载路径https://ftp.gnu.org/pub/gnu/libiconv/注意这里选择libiconv-1.11.1版本,因为之后的版本没有Makefile.msvc ...
- NDK中使用pthread多线程中自己写的一个BUG
在使用pthread进行NDK中的多线程开发时,自己写了一个BUG, void *darkGrayThread(void *args) { ThreadParam *param = (ThreadPa ...
- php 接口与前端数据交互实现
最近在做前后端数据交互的尝试,也跳了很多坑,使用的是php+bootstrap-table+js,把一些收获记录在这里,方便查询. 这个小项目,仅有3个文件,分别为: crud.html data.p ...
- html常用标签学习笔记
本文内容: 前言:本文讲述的内容包括几类常用标签,以及这些标签的一些常用属性(有一些属性由于已经有CSS样式来代替,所以对于一些不重要的这里选择不讲) 排版标签 段落标签:p div span 标题标 ...
- (python)面向对象
一.面向对象概述 要了解面向对象,就需要先了解面向过程的概念,那么什么是面向过程编程呢?最具代表性的就是C语言了,所谓面向过程编程就是在做一件事的时候,需要按步骤进行,第一步干什么,第二步干什么,这种 ...
- win10 出现0x80072efd错误
0x80072efd 0x80072efd 是网络问题,windows更新或windows应用商店出现0x80072efd问题,请检查本机代理,是否开着小飞机(Shadowsocks)之类的代理工具. ...
- [Hive_5] Hive 的 JDBC 编程
0. 说明 Hive 的 JDBC 编程 1. hiveserver2 介绍 hiveserver2 是 Hive 的 JDBC 接口,用户可以连接此端口来连接 Hive 服务器 JDBC 驱动类为 ...
- DB2常见错误信息
000 00000 SQL语句成功完成01xxx SQL语句成功完成,但是有警告+012 01545 未限定的列名被解释为一个有相互联系的引用+098 01568 动态SQL语句用分号结束+100 0 ...
- 创建 tomcat 服务的镜像
如何设计 Tomcat 的 Dockerfile $ sudo docker search tomcat |wc -l 285 在 dockerhub 上搜索与 tomcat 相关的镜像,有如此之多的 ...
- 【HNOI2016】最小公倍数
[HNOI2016]最小公倍数 容易想到先将所有边按\(a\)排序,然后处理\(b\).(然后我就不会了 我们按\(a\)的权值分块,处理\(a\)权值位于第\(k\)个块的询问的时候,我们先将询问按 ...