[Gym-101512C] 凸包+最远点对
找最大的四边形或者三角形面积,先求凸包,然后枚举两个点,再通过旋转,找最大的另两个点
#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] 凸包+最远点对的更多相关文章
- Saint John Festival Gym - 101128J (凸包二分)
Problem J: Saint John Festival \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 给出\(n\)个大点,和\(m\ ...
- poj2187凸包最远点对
暴力过了 #include<map> #include<set> #include<cmath> #include<queue> #include< ...
- OpenCV学习(30) 轮廓defects
上一篇教程中,我们学习了如何计算轮廓的凸包,其实对一个轮廓而言,可能它的凸包和它本身是重合的,也有可能不是重合的.比如下面左边图像的轮廓本身就是凸包,而右边图像的轮廓则不是.我们可以通过函数bool ...
- POJ(2187)用凸包求最远点对
Beauty Contest http://poj.org/problem?id=2187 题目描述:输入n对整数点,求最距离远的点对,输出他们距离的平方和 算法:拿到这个题,最朴素的想法就是用2层循 ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- Gym 101606B - Breaking Biscuits - [凸包+旋转卡壳][凸包的宽度]
题目链接:https://codeforces.com/gym/101606/problem/B 题解: 对于给出的 $n$ 个点,先求这些点的凸包,然后用旋转卡壳求出凸包的宽度(Width (min ...
- 【凸包板题】Gym - 101484E E. Double Fence
http://codeforces.com/gym/101484/problem/E 题解 凸包板题 #define _CRT_SECURE_NO_WARNINGS #include<cmath ...
- gym 101164 H.Pub crawl 凸包
题目链接:http://codeforces.com/gym/101164/attachments 题意:对于已知的 n 个二维坐标点,要求按照某种特定的连线方式将尽可能多的点连接(任意相邻的 3 个 ...
- [codeforces/gym/101350/L]维护“凸包”
题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...
随机推荐
- element-ui中下拉菜单中的@click事件不会触发的问题
只需要将@click=“fun()”改为@click.native=“fun()”,即可监听下拉菜单的点击事件. 如图所示: 嗯,就酱~
- 内置函数:max 用法
内置函数——max Python max内置函数 max(iterable, *[, key, default]) max(arg1, arg2, *args[, key]) Return the l ...
- 基于nodejs的wiki系统
jingo: https://github.com/claudioc/jingo nodewiki: https://github.com/nhoss2/nodewiki Tidd ...
- 003 F-47创建预付定金请求检查增强-20150819.docx
Enhancement SE38:LEINRF26 操作F-47,预付定金请求回车时,检查输入的采购订单项目发票视图,预付定金% 栏位,若为空,则报错,不为空可继续. 检查逻辑:检查采购凭证项 ...
- 20170330 ABAP代理生成
在线文档ABAP代理生成, ABAP 代理生成(事物SPROXY)使您能够通过使用企业服务资源中企业服务资源库中 的接口描述在SAP系统中生成ABAP代理对象. ABAP代理生成概览: 1.代理标识, ...
- Linxu下jenkins部署和基本配置
一.OpenJdk1.8安装(tomcat 和 jenkins都依赖与java) ubuntu apt-cache search openjdk #使用apt-cache搜索可以直接使用 ...
- Eclipse 变量高亮显示设置
A:Window-> preferences->java->Editor->Mark Occurences Local variables就是变量的高亮显示
- Spring笔记:事务管理
Spring笔记:事务管理 事务管理 Spring事务管理是通过SpringAOP去实现的.默认情况下Spring在执行方法抛出异常后,引发事务回顾,当然你可以用拦截器或者配置去改变它们. 这部门内容 ...
- Using中return对象
class Program { static void Main(string[] args) { Test test = new Test(); var a = test.CreateA(); te ...
- Array.asList:数组转list
String s[]={"aa","bb","cc"}; List<String> sList=Arrays.asList(s) ...