Luogu-4166 [SCOI2007]最大土地面积
求平面内四边形的最大面积
显然四个端点都应该在凸包上,就先求凸包,然后\(n^2\)枚举四边形对角线,对于一个点\(i\),顺序枚举\(j\),同时用旋转卡壳的方法去找离对角线最远的两个点。总时间复杂度\(n^2\)
luogu一遍过,但不知道为什么BZOJ死活TLE...
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e4+100;
const double eps=1e-9;
struct Vector{
double x,y;
Vector(double a=0,double b=0){
x=a,y=b;
}
};
struct Point{
double x,y;
Point(double a=0,double b=0){
x=a,y=b;
}
}a[maxn],tmp[maxn];
int dcmp(double x){return fabs(x)<eps?0:x>0;}
double operator * (Vector a,Vector b){return a.x*b.y-a.y*b.x;}
bool operator < (Point a,Point b){return a.x==b.x?a.y<b.y:a.x<b.x;}
bool operator == (Point a,Point b){return a.x==b.x&&a.y==b.y;}
Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double len(Vector x){return sqrt(dot(x,x));}
int n,m;
void tb(Point *p,int &n){
if(n==1) return;
sort(p+1,p+n+1);
tmp[m=1]=p[1];
for(int i=2;i<=n;i++){
while(m>1&&dcmp((tmp[m]-tmp[m-1])*(p[i]-tmp[m-1]))<=0)
m--;
tmp[++m]=p[i];
}
int k=m;
for(int i=n-1;i>=1;i--){
while(m>k&&dcmp((tmp[m]-tmp[m-1])*(p[i]-tmp[m-1]))<=0)
m--;
tmp[++m]=p[i];
}
n=m-1;
for(int i=1;i<m;i++)
p[i]=tmp[i];
}
double dists(Point p,Point a,Point b){
Vector v1=b-a,v2=p-a;
return fabs(v1*v2/len(v1));
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
tb(a,n);
double ans=0;
a[n+1]=a[1];
for(int i=1;i<=n;i++){
int x=(i+2)%n+1,y=i%n+1;
for(int j=i+2;j<=n;j++){
while(x%n+1!=i&&dcmp(dists(a[x+1],a[i],a[j])-dists(a[x],a[i],a[j]))>0)
x=x%n+1;
while(y%n+1!=j&&dcmp(dists(a[y+1],a[i],a[j])-dists(a[y],a[i],a[j]))>0)
y=y%n+1;
double z=fabs((a[j]-a[i])*(a[x]-a[y]))/2;
ans=max(ans,z);
}
}
printf("%.3lf\n",ans);
return 0;
}
Luogu-4166 [SCOI2007]最大土地面积的更多相关文章
- luogu P4166 [SCOI2007]最大土地面积 凸包 旋转卡壳
LINK:最大土地面积 容易想到四边形的边在凸包上面 考虑暴力枚举凸包上的四个点计算面积. 不过可以想到可以直接枚举对角线的两个点找到再在两边各找一个点 这样复杂度为\(n^3\) 可以得到50分. ...
- bzoj1069 SCOI2007 最大土地面积
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2560 Solved: 983 Description ...
- bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2277 Solved: 853[Submit][Stat ...
- BZOJ 1069: [SCOI2007]最大土地面积 [旋转卡壳]
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2978 Solved: 1173[Submit][Sta ...
- bzoj1069 [SCOI2007]最大土地面积 旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3767 Solved: 1501[Submit][Sta ...
- [BZOJ1069][SCOI2007]最大土地面积 凸包+旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3669 Solved: 1451[Submit][Sta ...
- BZOJ 1069: [SCOI2007]最大土地面积(旋转卡壳)
题目链接~ 1069: [SCOI2007]最大土地面积 思路很简单,极角排序求完凸包后,在凸包上枚举对角线,然后两边分别来两个点旋转卡壳一下,搞定! 不过计算几何的题目就是这样,程序中间的处理还是比 ...
- 1069: [SCOI2007]最大土地面积
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2961 Solved: 1162[Submit][Sta ...
- [Bzoj1069][Scoi2007]最大土地面积(凸包)(旋转卡壳)
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3629 Solved: 1432[Submit][Sta ...
- Luogu 2470 [SCOI2007]压缩
和Luogu 4302 [SCOI2003]字符串折叠 差不多的想法,区间dp 为了计算方便,我们可以假设区间[l, r]的前面放了一个M,设$f_{i, j, 0/1}$表示区间$[i, j]$中是 ...
随机推荐
- Elasticsearch5.X IN Windows 10 系列文章(1)
系统类型:windows10 64位家庭版 ElasticSearch版本: 5.5.1 (最新稳定版为5.5.2),由于用到IK中文分词插件,最新版本没有5.5.2 ,所以使用5.5.1 日期:2 ...
- 【Axure插件】之浏览器打开失败
下载地址:https://files.cnblogs.com/files/Owen-ET/AxureRP_for_chorme_0_6_2.xml 下载后的文件后缀修改为:AxureRP_for_ch ...
- SVM支持向量机
支持向量机(Support Vector Machine,SVM)是效果最好的分类算法之中的一个. 一.线性分类器: 一个线性分类器就是要在n维的数据空间中找到一个超平面,通过这个超平面能够把两类数据 ...
- 【BZOJ3331】[BeiJing2013]压力 Tarjan求点双
[BZOJ3331][BeiJing2013]压力 Description 如今,路由器和交换机构建起了互联网的骨架.处在互联网的骨干位置的核心路由器典型的要处理100Gbit/s的网络流量.他们每天 ...
- And Then There Was One(约瑟夫环)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- visual studio2017 无法添加引用 未能加载包ReferenceManagerPackage not such interface support 解决方法
安装完visual studio 2017 后添加引用总是提示 未能加载包ReferenceManagerPackage, 这个问题困扰了两天,直到在网上看到了下面这一段 I just got thi ...
- 洛谷 P2051 [SDOI2009]学校食堂
传送门- 题目分析:首先,我们先看看做菜时间的运算机制.$(A~\texttt{or}~B)-(A~\texttt{and}~B)$这个试子看起来有点复杂(因为我太菜了),仔细想想,是不是可以转化为$ ...
- RxJava2 源代码解析(一)
转载请标明出处: http://blog.csdn.net/zxt0601/article/details/61614799 本文出自:[张旭童的博客](http://blog.csdn.net/zx ...
- python+NLTK 自然语言学习处理四:获取文本语料和词汇资源
在前面我们通过from nltk.book import *的方式获取了一些预定义的文本.本章将讨论各种文本语料库 1 古腾堡语料库 古腾堡是一个大型的电子图书在线网站,网址是http://www.g ...
- Python字典的入门案例
查看python版本: [root@localhost ~]# python -V Python 2.7.5 1.基本的字典操作 案例1:简单电话本实现 [root@localhost ~]# vim ...