题目链接

又调了我两个多小时巨亏

直接\(O(n^4)\)枚举4个点显然不行。

数据范围提示我们需要一个\(O(n^2)\)的算法。

于是\(O(n^2)\)枚举对角线,然后在这两个点两边各找一个点使其和对角线构成的三角形面积最大,也就是叉积的绝对值最大。显然具有单调性,于是旋转卡壳维护。

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 50010;
const double eps = 1e-8;
struct point{
double x, y;
}p[MAXN];
inline double sig(double x){
return (x > eps) - (x < -eps);
}
int operator == (point a, point b){
return a.x == b.x && a.y == b.y;
}
double operator * (point a, point b){ // a x b
return a.x * b.y - b.x * a.y;
}
point operator - (point a, point b){ // a - b
return (point){ a.x - b.x, a.y - b.y };
}
point operator + (point a, point b){ // a + b
return (point){ a.x + b.x, a.y + b.y };
}
int cmp(const point a, const point b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
inline int judge(point a, point b, point c){ //Kab > Kac
return (b.y - a.y) * (c.x - a.x) >= (c.y - a.y) * (b.x - a.x);
}
inline double calc(point a, point b, point c){
return fabs((b - a) * (c - a));
}
int n, top, tp;
point st[MAXN], ts[MAXN];
double ans = 0;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p + 1, p + n + 1, cmp);
st[0] = (point){2434321, 2515215};
for(int i = 1; i <= n; ++i){
if(p[i] == st[top]) continue;
while(top > 1 && judge(st[top - 1], st[top], p[i])) --top;
st[++top] = p[i];
}
for(int i = 1; i <= n; ++i){
if(p[i] == ts[tp]) continue;
while(tp > 1 && !judge(ts[tp - 1], ts[tp], p[i])) --tp;
ts[++tp] = p[i];
}
for(int i = tp - 1; i; --i) st[++top] = ts[i];
st[0] = st[--top];
for(int i = 1; i < top; ++i){
int k = i + 1, l = (i + 3) % top;
for(int j = i + 2; j <= top; ++j){
while(sig(calc(st[i], st[j], st[k]) - calc(st[i], st[j], st[k + 1])) < 0) if(++k > top) k = 1;
while(sig(calc(st[i], st[j], st[l]) - calc(st[i], st[j], st[l + 1])) < 0) if(++l > top) l = 1;
ans = max(ans, (calc(st[i], st[j], st[k]) + calc(st[i], st[j], st[l])));
}
}
printf("%.3lf\n", ans / 2);
return 0;
}

【洛谷 P4166】 [SCOI2007]最大土地面积(凸包,旋转卡壳)的更多相关文章

  1. luogu P4166 [SCOI2007]最大土地面积 凸包 旋转卡壳

    LINK:最大土地面积 容易想到四边形的边在凸包上面 考虑暴力枚举凸包上的四个点计算面积. 不过可以想到可以直接枚举对角线的两个点找到再在两边各找一个点 这样复杂度为\(n^3\) 可以得到50分. ...

  2. bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积

    在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...

  3. [BZOJ1069][SCOI2007]最大土地面积 凸包+旋转卡壳

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 3669  Solved: 1451[Submit][Sta ...

  4. bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳

    题目大意: 二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大 题解: 很容易发现这四个点一定在凸包上 所以我们枚举一条边再旋转卡壳确定另外的两个点即可 旋(xuan2)转(zhua ...

  5. bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2277  Solved: 853[Submit][Stat ...

  6. 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳

    因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...

  7. [SCOI2007]最大土地面积(旋转卡壳)

    首先,最大四边形的四个点一定在凸包上 所以先求凸包 有个结论,若是随机数据,凸包包括的点大约是\(\log_2n\)个 然鹅,此题绝对不会这么轻松,若\(O(n^4)\)枚举,只有50分 所以还是要想 ...

  8. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  9. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  10. Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)

    题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...

随机推荐

  1. 【vue】vue安装卡住/报错

    网上有很多教程怎么安装: 安装cnpmnpm install -g cnpm --registry=https://registry.npm.taobao.org 升级npmcnpm install ...

  2. Q3 大型科技公司季报

    1. alphabet Alphabet(谷歌母公司)今天发布了截至9月30日的2018财年第三季度财报.报告显示,Alphabet第三季度总营收为337.40亿美元,比上年同期的277.72亿美元增 ...

  3. 使用python操作Memcache、Redis、RabbitMQ、

    Memcache 简述: Memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的.需要 ...

  4. Java 中 Vector、ArrayList、List 使用深入剖析

    线性表,链表,哈希表是常用的数据结构,在进行Java开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构.这些类均在java.util包中.本文试图通过简单的描述,向读者阐述各个类的作用以 ...

  5. 在js和C#中split应用和去除字符串分组后的空值

    如字符串 string answer="A,B,D,",在 js和 C#按","分成数组 js: , useranswer.length - ).split(& ...

  6. Spring Cloud Sleuth服务跟踪

    监控 使用zipkin(https://zipkin.io/) 监控服务构建: (普通的springBoot项目) <!--引入的zipkinServer依赖--> <depende ...

  7. Java虚拟机的内存管理

    众所周知,Java程序员写的代码是没有办法控制Java对象的内存释放的,完全有JVM暗箱操作. 虽然程序员把内存的释放的任务都交给了Java虚拟机,但是并不代表Java程序就不存在内存泄漏. 反而,某 ...

  8. (转)Ubuntu 17.04_64上搭建巡风扫描系统(资产信息漏洞扫描内网神器)

    巡风简介 巡风是一款适用于企业内网的漏洞快速应急.巡航扫描系统,通过搜索功能可清晰的了解内部网络资产分布情况,并且可指定漏洞插件对搜索结果进行快速漏洞检测并输出结果报表.其主体分为两部分:网络资产识别 ...

  9. HDU1863畅通工程---并查集+最小生成树

    #include<cstdio> #include<algorithm> #define MAX 105 struct edge { int from,to; long lon ...

  10. 洛谷 P1410 子序列(DP)

    这题的题解的贪心都是错误的...正解应该是个DP 考虑有哪些有关的条件:两个序列的当前长度, 两个序列的末尾数, 把这些都压进状态显然是会GG的 考虑两个长度加起来那一位的数一定是其中一个序列的末尾, ...