找最大的四边形或者三角形面积,先求凸包,然后枚举两个点,再通过旋转,找最大的另两个点

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; void debug(){cout<<-<<endl;} struct point{
ll x,y;
};
point p[N],s[N];
int top,n;
ll dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
ll dis(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
ll area(point p1,point p2,point p3)
{
return fabs(dir(p1,p2,p3));
}
bool comp(point a,point b)
{
ll te=dir(p[],a,b);
if(te<)return ;
if(te==&&dis(p[],a)<dis(p[],b))return ;
return ;
}
void graham()
{
int pos,minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
top=;
for(int i=;i<=n;i++)
{
while(dir(s[top-],s[top],p[i])>=&&top>=)top--;
s[++top]=p[i];
}
//cout<<top<<endl;
if(top==)
{
cout<<area(s[],s[],s[])/;
if(area(s[],s[],s[])&)cout<<".5";
cout<<endl;
return ;
}
else if(top<)
{
cout<<<<endl;
return ;
}
/* for(int i=0;i<top;i++)
cout<<s[i].x<<" "<<s[i].y<<endl;*/
ll ans=;
for(int i=;i<top;i++)
{
int j,a1=(i+)%top,a2=(i+)%top;
for(j=(i+)%top;j!=i;j=(j+)%top)
{
while(a1!=j&&area(s[(a1+)%top],s[i],s[j])>=area(s[a1],s[i],s[j]))a1=(a1+)%top;
while(a2!=i&&area(s[(a2+)%top],s[i],s[j])>=area(s[a2],s[i],s[j]))a2=(a2+)%top;
ans=max(ans,area(s[a1],s[i],s[j])+area(s[a2],s[i],s[j]));
}
}
cout<<ans/;
if(ans&)cout<<".5";
cout<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout<<setiosflags(ios::fixed)<<setprecision();
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<n;i++)cin>>p[i].x>>p[i].y;
graham();
}
return ;
}
/********************
3
6
0 0
3 7
10 0
11 6
0 10
10 10
5
0 0
-2 -2
3 -2
0 1
0 3
10
3 1
4 1
5 9
2 6
5 3
5 8
9 7
9 3
2 3
8 4
********************/

[Gym-101512C] 凸包+最远点对的更多相关文章

  1. Saint John Festival Gym - 101128J (凸包二分)

    Problem J: Saint John Festival \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 给出\(n\)个大点,和\(m\ ...

  2. poj2187凸包最远点对

    暴力过了 #include<map> #include<set> #include<cmath> #include<queue> #include< ...

  3. OpenCV学习(30) 轮廓defects

    上一篇教程中,我们学习了如何计算轮廓的凸包,其实对一个轮廓而言,可能它的凸包和它本身是重合的,也有可能不是重合的.比如下面左边图像的轮廓本身就是凸包,而右边图像的轮廓则不是.我们可以通过函数bool ...

  4. POJ(2187)用凸包求最远点对

    Beauty Contest http://poj.org/problem?id=2187 题目描述:输入n对整数点,求最距离远的点对,输出他们距离的平方和 算法:拿到这个题,最朴素的想法就是用2层循 ...

  5. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

  6. Gym 101606B - Breaking Biscuits - [凸包+旋转卡壳][凸包的宽度]

    题目链接:https://codeforces.com/gym/101606/problem/B 题解: 对于给出的 $n$ 个点,先求这些点的凸包,然后用旋转卡壳求出凸包的宽度(Width (min ...

  7. 【凸包板题】Gym - 101484E E. Double Fence

    http://codeforces.com/gym/101484/problem/E 题解 凸包板题 #define _CRT_SECURE_NO_WARNINGS #include<cmath ...

  8. gym 101164 H.Pub crawl 凸包

    题目链接:http://codeforces.com/gym/101164/attachments 题意:对于已知的 n 个二维坐标点,要求按照某种特定的连线方式将尽可能多的点连接(任意相邻的 3 个 ...

  9. [codeforces/gym/101350/L]维护“凸包”

    题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...

随机推荐

  1. MySQL中数据中设计中的范式与反范式

    设计关系数据库时,遵从不同的规范要求,设计出合理的关系型数据库,这些不同的规范要求被称为不同的范式,各种范式呈递次规范,越高的范式数据库冗余越小.但是有些时候一昧的追求范式减少冗余,反而会降低数据读写 ...

  2. iOS 载入图片选择imageNamed 方法还是 imageWithContentsOfFile?

    Apple官方的文档为生成一个UIImage对象提供了两种方法: 1. imageNamed,其參数为图片的名字. 2. imageWithContentsOfFile,其參数也是图片文件的路径. 那 ...

  3. Google Cloud Platfrom中运行基础的Apache Web服务

    Links: https://cloud.google.com/compute/docs/tutorials/basic-webserver-apache 步骤: 1.安装Apache 2.重写Apa ...

  4. Hadoop学习基础之三:MapReduce

    现在是讨论这个问题的不错的时机,因为最近媒体上到处充斥着新的革命所谓“云计算”的信息.这种模式需要利用大量的(低端)处理器并行工作来解决计算问题.实际上,这建议利用大量的低端处理器来构建数据中心,而不 ...

  5. c# 如何设置透明画刷

    使用solidBrush新建画刷,定义画刷的颜色为透明色 Brush b = new SolidBrush(Color.FromArgb(50, Color.Green)); 这里的50是透明度的设置 ...

  6. LeetCode:路径总和【112】

    LeetCode:路径总和[112] 题目描述 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例 ...

  7. 深度学习1--ubuntu14.04+win10双系统

    相当多的内容参考的百度经验https://jingyan.baidu.com/article/eb9f7b6d79a7b4869364e885.html?qq-pf-to=pcqq.group 还可以 ...

  8. 自己动手编译Android源码(超详细)

    http://www.jianshu.com/p/367f0886e62b 在Android Studio代码调试一文中,简单的介绍了代码调试的一些技巧.现在我们来谈谈android源码编译的一些事. ...

  9. tomcat8配置tomcat-users.xml不生效

    一般想进入tomcat管理后台,只要在tomcat-users.xml配置文件中添加一下内容即可 <role rolename="manager-gui"/> < ...

  10. 20145240 《Java程序设计》第一次实验报告

    20145240 <Java程序设计>第一次实验报告 实验内容 一.命令行下java程序开发 1.建立Code目录,输入mkdir 20145240命令建立实验目录,并使用dir命令查看目 ...