CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)
You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which area exceeds S.
Alyona tried to construct a triangle with integer coordinates, which contains all n points and which area doesn't exceed 4S, but, by obvious reason, had no success in that. Please help Alyona construct such triangle. Please note that vertices of resulting triangle are not necessarily chosen from n given points.
Input
In the first line of the input two integers n and S (3 ≤ n ≤ 5000, 1 ≤ S ≤ 1018) are given — the number of points given and the upper bound value of any triangle's area, formed by any three of given n points.
The next n lines describes given points: ith of them consists of two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — coordinates of ith point.
It is guaranteed that there is at least one triple of points not lying on the same line.
Output
Print the coordinates of three points — vertices of a triangle which contains all n points and which area doesn't exceed 4S.
Coordinates of every triangle's vertex should be printed on a separate line, every coordinate pair should be separated by a single space. Coordinates should be an integers not exceeding 109 by absolute value.
It is guaranteed that there is at least one desired triangle. If there is more than one answer, print any of them.
Example
4 1
0 0
1 0
0 1
1 1
-1 0
2 0
0 2
题意:给定N个点,保证最大三角形面积不超过S,现在让你找一个面积不超过4*S的三角形,使之覆盖所有点。
思路:找到最大三角形X,然后按照平行四边形的样子,对称出3个三角形。即可覆盖所有点,否则可以反证X的面积不是最大。
所以按照上一题一样,先求凸包,然后求最大三角形的坐标,然后对称。 如图:

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define RC rotating_calipers
using namespace std;
const int maxn=;
struct point{
ll x,y;
point(ll x=,ll y=):x(x),y(y){}
bool operator <(const point &c) const { return x<c.x||(x==c.x&&y<c.y);}
point operator -(const point &c)const { return point(x-c.x,y-c.y);}
};
ll det(point A,point B){ return A.x*B.y-A.y*B.x;}
ll det(point O,point A,point B){ return det(A-O,B-O);}
point a[maxn],ch[maxn],A,B,C;
void convexhull(int n,int &top)
{
sort(a+,a+n+); top=;
for(int i=;i<=n;i++){
while(top>&&det(ch[top-],ch[top],a[i])<=) top--;
ch[++top]=a[i];
}
int ttop=top;
for(int i=n-;i>=;i--){
while(top>ttop&&det(ch[top-],ch[top],a[i])<=) top--;
ch[++top]=a[i];
}
}
void rotating_calipers(point p[],int top)
{
ll ans=; int now;
rep(i,,top-){
int now=i+;
rep(j,i+,top-){
while(now<=top&&abs(det(p[i],p[j],p[now]))<abs(det(p[i],p[j],p[now+]))){
now++;
}
ll tmp=abs(det(p[i],p[j],p[now]));
if(tmp>ans) ans=tmp,A=p[i],B=p[j],C=p[now];
}
}
}
int main()
{
int N; ll S;
scanf("%d%I64d",&N,&S);
for(int i=;i<=N;i++) scanf("%I64d%I64d",&a[i].x,&a[i].y);
int top; convexhull(N,top);
RC(ch,top-);
printf("%I64d %I64d\n",A.x+B.x-C.x,A.y+B.y-C.y);
printf("%I64d %I64d\n",A.x+C.x-B.x,A.y+C.y-B.y);
printf("%I64d %I64d\n",B.x+C.x-A.x,B.y+C.y-A.y);
return ;
}
CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)的更多相关文章
- POJ 2079 Triangle 旋转卡壳求最大三角形
求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...
- CodeForces 682E Alyona and Triangles (计算几何)
Alyona and Triangles 题目连接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/J Description You ar ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- UVa 1453 - Squares 旋转卡壳求凸包直径
旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
旋转卡壳求最小矩形覆盖的模板题. 因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可. #include<cstdio> # ...
- POJ2187 旋转卡壳 求最长直径
给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...
- 「POJ-3608」Bridge Across Islands (旋转卡壳--求两凸包距离)
题目链接 POJ-3608 Bridge Across Islands 题意 依次按逆时针方向给出凸包,在两个凸包小岛之间造桥,求最小距离. 题解 旋转卡壳的应用之一:求两凸包的最近距离. 找到凸包 ...
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
随机推荐
- PAT 天梯赛 L1-025. 正整数A+B 【字符串处理】
题目链接 https://www.patest.cn/contests/gplt/L1-025 思路 注意 输入字符串B的时候 要用getline 因为 可能存在空格 然后就把字符串 转化成 数字 并 ...
- android 7.0 (nougat)的编译优化-ninja
http://blog.csdn.net/songjam/article/details/52640501 版权声明:本文为博主原创文章,未经博主允许不得转载. 从官方的定义,ninja大大缩短了an ...
- MySQL-5.7权限详解
1.MySQL权限级别 (1)全局性管理权限 作用于整个MySQL实例级别 *.*代表所有数据库的权限 mysql> grant all on *.* to 'test'@'%'; Query ...
- jQuery图片下滑切换焦点图
在线演示 本地下载
- INSPIRED启示录 读书笔记 - 第6章 招聘产品经理
产品经理应有的特质 个人素质和态度:技术可以学习,素质却难以培养,有些素质是成功的产品经理必不可少的 对产品的热情:对产品有一种本能的热爱,是夜以继日克服困难.完善产品的动力 用户立场:能换位思考,能 ...
- JSP JavaBeans
Javabean的设计原则 公有类 无参公有构造方法 私有属性 getter和setter方法 在Jsp页面中如何使用Javabeans? 像使用普通Java类一样,创建JavaBeans实例. 在J ...
- JAVA 写中文字符串到指定文件 中文乱码 问题解决
之前试过下面代码里面的注释掉的 方法,都不行,后来想到了不如指定编码格式试试,果真可以了. String as= “中文字符”; //byte[] b = as.getBytes(); try{ Fi ...
- java 发送http 的get|post 请求
<div> package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import jav ...
- Python-flask中数据库连接池DBUtils
一.DBUtils DBUtils是Python的一个用于实现数据库连接池的模块. 连接池的三种模式: 第一种模式: 它的缺点:每一次请求反复创建数据库的链接,链接的次数太多 ...
- Hadoop- Namenode经常挂掉 IPC's epoch 9 is less than the last promised epoch 10
如题出现Namenode经常挂掉 IPC's epoch 9 is less than the last promised epoch 10, 2019-01-03 05:36:14,774 INFO ...