【洛谷 P4166】 [SCOI2007]最大土地面积(凸包,旋转卡壳)
题目链接
又调了我两个多小时巨亏
直接\(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]最大土地面积(凸包,旋转卡壳)的更多相关文章
- luogu P4166 [SCOI2007]最大土地面积 凸包 旋转卡壳
		
LINK:最大土地面积 容易想到四边形的边在凸包上面 考虑暴力枚举凸包上的四个点计算面积. 不过可以想到可以直接枚举对角线的两个点找到再在两边各找一个点 这样复杂度为\(n^3\) 可以得到50分. ...
 - bzoj1069: [SCOI2007]最大土地面积  凸包+旋转卡壳求最大四边形面积
		
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
 - [BZOJ1069][SCOI2007]最大土地面积  凸包+旋转卡壳
		
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3669 Solved: 1451[Submit][Sta ...
 - 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 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
 - Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)
		
题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...
 
随机推荐
- UML之Enterprise Architect使用
			
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:UML之Enterprise Architect使用 本文地址:http://tech ...
 - 增加响应header让ajax支持跨域
			
ajax请求数据步骤 发送请求--->浏览器接受响应--->判断是否是同域下 是的话,就把响应数据返回给ajax.不是的话就提醒禁止跨域请求. 现在可以在响应头重增加 header(&qu ...
 - 使用vue-cli3新建一个项目,并写好基本配置
			
1. 使用vue-cli3新建项目: https://cli.vuejs.org/zh/guide/creating-a-project.html 注意,我这里用gitbash不好选择选项,我就用了基 ...
 - py27使用redis
			
1.安装redis pip install redis 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/
 - MySQL专题 2 数据库优化 Slow Query log
			
MySQL Server 有四种类型的日志——Error Log.General Query Log.Binary Log 和 Slow Query Log. 第一个是错误日志,记录 mysqld 的 ...
 - 第87天:HTML5中新选择器querySelector的使用
			
一.HTML5新选择器 1.document.querySelector("selector");selector:根据CSS选择器返回第一个匹配到的元素,如果没有匹配到,则返回n ...
 - 【bzoj2829】信用卡凸包  凸包
			
题目描述 输入 输出 样例输入 26.0 2.0 0.00.0 0.0 0.02.0 -2.0 1.5707963268 样例输出 21.66 题解 凸包 傻逼题,答案显然为:所有圆心构成的凸包周长+ ...
 - 【Java并发编程】之三:线程挂起、恢复与终止的正确方法
			
挂起和恢复线程  Thread 的API中包含两个被淘汰的方法,它们用于临时挂起和重启某个线程,这些方法已经被淘汰,因为它们是不安全的,不稳定的.如果在不合适的时候挂起线程(比如,锁定共享资源时), ...
 - poj1958——Strange Towers of Hanoi
			
The teacher points to the blackboard (Fig. 4) and says: "So here is the problem: There are thre ...
 - BZOJ1187:[HNOI2007]神奇游乐园——题解
			
http://www.lydsy.com/JudgeOnline/problem.php?id=1187 Description 经历了一段艰辛的旅程后,主人公小P乘坐飞艇返回.在返回的途中,小P发现 ...