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

#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 第四天

    回顾 列属性: 主键, 自增长, 唯一键     关系: 一对一,一对多和多对多 范式: 三层范式 1NF: 字段设计必须符合原子性 2NF: 不存在部分依赖(没有复合主键) 3NF: 不存在传递依赖 ...

  2. Linux中的系统挂载文件/etc/fstab

    [root@localhost ~]# cat /etc/fstab ## /etc/fstab# Created by anaconda on Wed Oct 5 15:21:46 2016## A ...

  3. vim常规操作

    原文地址 三种模式 一般模式:可以进行复制.粘贴和删除等操作 编辑模式:按i或a进入编辑模式,按Esc回到一般模式 命令模式:按/或?或:进入命令模式,按Esc回到一般模式 移动操作 h j k l: ...

  4. windows8.1电话激活密钥

    请断网安装Windows 8.1核心版:334NH-RXG76-64THK-C7CKG-D3VPT Windows 8.1专业版:XHQ8N-C3MCJ-RQXB6-WCHYG-C9WKB

  5. MyEclipse工具栏的隐藏与显示及自定义

    Myeclipse的工具栏 1.隐藏 工具栏---->右键---->hide toolbar 2.显示     window ----> show toolbar 3.自定义     ...

  6. Kattis - prva 【字符串】

    题意 从上到下 或者 从左到右 组成的长度 >= 2 的字符串 如果遇到 # 就断掉 输出 字典序最小的那一个 思路 只要从上到下 和从左到右 分别遍历一遍,将 长度 >= 2 的字符串 ...

  7. Windos Server 2008 FTP 服务安装

    安装服务:FTP 系统环境:Windos 2008 R2 x64 安装FTP服务 管理-->角色-->添加角色-->Web 服务器 IIS 测试

  8. 对matrix,dataframe的操作函数

    1.每行(列)的平均值:rowMeans() ; colMeans() 输入:数值型矩阵:数值型数据框 输出:向量 2.每行(列)的总和:rowSums() ;colSums() 输入:数值型矩阵,数 ...

  9. Kubernetes Metrics-Server

    github地址:https://github.com/kubernetes-incubator/metrics-server 官网介绍:https://kubernetes.io/docs/task ...

  10. hql join

    文章一: 1.用hql语句 ` String hql="select student.id, student.name ,class.name from student映射实体类名 as s ...