P4166 [SCOI2007]最大土地面积

news/2025/3/14 16:40:00/

传送门

首先,四边形的四个点肯定都在凸包上(别问我为什么我也不知道,感性理解一下好了)

那么我们可以求出凸包之后\(O(n^4)\)暴力枚举,据说在随机数据下凸包上的点只有\(O(logn)\)个可过

然而出题人大大的没有良心,上面那样写只有50分

我们考虑枚举对角线,那么剩下的两个点就是在这条对角线两边,也就是说要分别找到和这条边面积最大的点。发现这个可以用旋转卡壳来优化,计算面积用叉积,于是总的时间复杂度即为\(O(n^2)\)

//minamoto
#include<bits/stdc++.h>
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
using namespace std;
//template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
const int N=10005;
struct node{double x,y;}p[N],st[N];
int n,k,top;double ans;
inline bool cmp(node a,node b){double A=atan2(a.y-p[1].y,a.x-p[1].x);double B=atan2(b.y-p[1].y,b.x-p[1].x);return A!=B?A<B:a.x<b.x;
}
inline double cross(node a,node b,node c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
int main(){
//  freopen("testdata.in","r",stdin);scanf("%d",&n),k=1;fp(i,1,n){scanf("%lf%lf",&p[i].x,&p[i].y);if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))k=i;}swap(p[1],p[k]),sort(p+2,p+1+n,cmp);st[0]=p[1],st[1]=p[2],top=1;fp(i,3,n){while(top&&cross(st[top-1],p[i],st[top])>=0)--top;st[++top]=p[i];}st[++top]=p[0];if(top==4)return printf("%.3lf\n",(cross(st[0],st[1],st[2])+cross(st[2],st[3],st[0]))/2);fp(i,0,top)for(register int j=i+2,k=i+1,l=(i+3)%top;j<top;++j){while(cross(st[i],st[k],st[j])<cross(st[i],st[k+1],st[j]))k=(k+1)%top;while(cross(st[j],st[l],st[i])<cross(st[j],st[l+1],st[i]))l=(l+1)%top;ans=max(ans,cross(st[i],st[k],st[j])+cross(st[j],st[l],st[i]));}printf("%.3lf\n",ans/2);return 0;
}

转载于:https://www.cnblogs.com/bztMinamoto/p/10000997.html


http://www.ppmy.cn/news/243418.html

相关文章

HDU 4166 Robot Navigation

题意&#xff1a; 一个机器人走迷宫 每一秒要么转向要么前进 问 最少时间的情况下有几种方案 思路&#xff1a; 记忆化搜索即可 简单bfs 代码&#xff1a; #include<cstdio> #include<iostream> #include<cstring> #include<string> #include&…

HDU4166【BFS】

题意&#xff1a; 给你一幅图&#xff0c;给你起点和终点&#xff0c;再给你机器人所面对的方向&#xff0c;机器人可以左转90&#xff0c;右转90&#xff0c;向前进一格&#xff0c;每种操作都是1秒&#xff0c;,求起点和终点最少花费下的路径条数&#xff0c;方案数&#xf…

[回文自动机 Manacher] BZOJ4166: 月宫的符卡序列

hash被卡… 本来以为是回文自动机裸题 发现fail树上一条链的节点表示的回文子串的中点是不一样的… 不过回文树上的链是一样的 那么用建出回文树&#xff08;我用回文自动机建的&#xff0c;manacher建不知道为什么WA了&#xff09;&#xff0c;然后找到以每个点为中点的最…

【BZOJ4166】月宫的符卡序列 Manacher+hash

【BZOJ4166】月宫的符卡序列 题解&#xff1a;题倒不难&#xff0c;就是有点恶心。 首先学习回文串的时候一定学到了这样一个结论&#xff1a;一个长度为n的串的本质不同的回文子串数量不超过n个。 那么我们就可以试图将所有回文串的价值都计算出来&#xff0c;这就需要我们先计…

洛谷P4166 [SCOI2007]最大土地面积

将四边形拆成两个三角形。旋转卡壳经典题。 #include <bits/stdc.h> using namespace std; typedef long long LL; typedef int lint; const int maxn 2001; const double eps 1e-12; const double PI acos(-1.0); int sgn(double x) {if(fabs(x) < eps)return 0;…

BZOJ 1069 Luogu P4166 最大土地面积 (凸包)

题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id1069 (luogu)https://www.luogu.org/problemnew/show/P4166 题解: 水题&#xff0c;凸包极角排序之后枚举凸四边形对角线\(i,j\)然后找面积最大的点\(k\)&#xff0c;\(k\)随着\(i,j\)是单调的 但是有个易错…

Android中的Intent(显示隐式)

Android中的Intent(显示&隐式) 显示Intent 显示Intent是明确目标Activity的类名 通过Intent(Context packageContext, Class<?> cls)构造方法Intent intent new Intent(this, SecondActivity.class) startActivity(intent);通过Intent的setComponent()方法Componen…

NLP的idea,看了就能水一篇论文

1.问题 在中文情感分析任务中,已有方法仅从单极、单尺度来考虑情感特征&#xff0c;无法充分挖掘和利用情感特征信息&#xff0c;模型性能不理想。 单级单尺度&#xff1a;只从一个方面学习文本的特征 多级多尺度&#xff1a;应该是分别从不同方面学习文本的特征&#xff0c…