Alyona and Triangles

题目连接:

http://acm.hust.edu.cn/vjudge/contest/121333#problem/J

Description

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.

Sample Input

4 1

0 0

1 0

0 1

1 1

Sample Output

-1 0

2 0

0 2

题意:

给出n个点,任意三个点组成的三角形面积不超过S;

构造一个大三角形覆盖上述所有n个点,并且面积不超过4S;

题解:

先找出最大的三角形;

再根据性质往三边拓展三个相同的三角形,面积即不超过4S;

找最大三角形:不停遍历n个点加入三角形点集合,可以证明复杂度不超过O(n^2);

(图盗用自@qscqesze同学~)

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define double LL
#define eps 1e-8
#define maxn 5100
#define mod 1000000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std; struct Point{
double x,y;
Point(){}
Point(double tx,double ty) {x=tx;y=ty;}
}p[maxn];; double xmul(Point p0,Point p1,Point p2)
{return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);} double triangle_area(Point a,Point b,Point c) {
return abs(xmul(a,b,c));
} int main(void)
{
//IN; int n; LL S;
while(scanf("%d %I64d", &n,&S) != EOF)
{
for(int i=1; i<=n; i++)
scanf("%I64d %I64d", &p[i].x,&p[i].y); bool flag = 1;
int a=1, b=2, c=3;
double ans = triangle_area(p[a],p[b],p[c]);
while(flag) {
flag = 0;
for(int i=1; i<=n; i++) {
double tmp;
tmp = triangle_area(p[a],p[b],p[i]);
if(tmp > ans) {
ans = tmp; c = i; flag = 1;
}
tmp = triangle_area(p[a],p[i],p[c]);
if(tmp > ans) {
ans = tmp; b = i; flag = 1;
}
tmp = triangle_area(p[i],p[b],p[c]);
if(tmp > ans) {
ans = tmp; a = i; flag = 1;
}
}
} cout << p[a].x+p[b].x-p[c].x << ' ' << p[b].y+p[a].y-p[c].y << endl;
cout << p[a].x+p[c].x-p[b].x << ' ' << p[c].y+p[a].y-p[b].y << endl;
cout << p[c].x+p[b].x-p[a].x << ' ' << p[b].y+p[c].y-p[a].y << endl;
} return 0;
}

CodeForces 682E Alyona and Triangles (计算几何)的更多相关文章

  1. Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化

    E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given ...

  2. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)

    You are given n points with integer coordinates on the plane. Points are given in a way such that th ...

  4. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  5. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  6. Codeforces 777C Alyona and Spreadsheet

    C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  7. cf682E Alyona and Triangles

    You are given n points with integer coordinates on the plane. Points are given in a way such that th ...

  8. Codeforces 1119E Pavel and Triangles (贪心)

    Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...

  9. codeforces 682C Alyona and the Tree(DFS)

    题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...

随机推荐

  1. Html,Css,Javascript及其他的注释方法详解

    一.HTML的注释方法<!-- html注释:START -->内容<!-- html注释:END --> 包含在“<!--”与“-->”之间的内容将会被浏览器忽略 ...

  2. POJ 2065 SETI(高斯消元)

    题目链接:http://poj.org/problem?id=2065 题意:给出一个字符串S[1,n],字母a-z代表1到26,*代表0.我们用数组C[i]表示S[i]经过该变换得到的数字.给出一个 ...

  3. TCP/IP 与OSI结构图

    OSI参考模型各层的作用 物理层:在物理媒体上传输原始的数据比特流. 数据链路层:将数据分成一个个数据帧,以数据帧为单位传输.有应有答,遇错重发. 网络层:将数据分成一定长度的分组,将分组穿过通信子网 ...

  4. linux系统设置服务开机启动3种方法,Linux开机启动程序详解

    linux系统设置服务开机启动 方法1:.利用ntsysv伪图形进行设置,利用root登陆 终端命令下输入ntsysv 回车:如下图     方法2:利用命令行chkconfig命令进行设置 简要说明 ...

  5. ogre, dx, opengl坐标矩阵

    opengl 右手坐标系 列向量 左乘 列主序存储矩阵osg   右手坐标系 行向量 右乘 行主序存储矩阵d3d       左手坐标系 行向量 右乘 行主序存储矩阵ogre    右手坐标系 列向量 ...

  6. poj 3264 Balanced Lineup (RMQ算法 模板题)

    RMQ支持操作: Query(L, R):  计算Min{a[L],a[L+1], a[R]}. 预处理时间是O(nlogn), 查询只需 O(1). RMQ问题 用于求给定区间内的最大值/最小值问题 ...

  7. UVa 10817 (状压DP + 记忆化搜索) Headmaster's Headache

    题意: 一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师. 每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两 ...

  8. Jqgrid入门-Jqgrid列数据拖动(七)

    上一章提到在Jqgrid中如何设置二级表头,这一章节主要探讨Jqgrid表格里面的数据如果实现拖动功能,比如你想把第一行的数据拖到当前页的最后一行,或者其他位置.     Jqgrid表格插件自己没有 ...

  9. python模拟http请求

    下文主要讲述如何利用python自带的库模拟http请求,为以后利用python做API测试做准备. 只讲述模拟http的过程,具体到自己用的时候,要以自己的应用为准做出适当的调整. #!coding ...

  10. CentOS6.2下fastDFS的完整安装和配置步骤

    centos6.2系统下安装配置FastDFS步骤: 1:安装libevent(libevent-2.0.16-stable) ##卸载系统自带libevent rpm -qa|grep libeve ...