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. ubuntu下android源码下载

    步骤一: 首先保证你的ubuntu系统电脑可以顺利游览google,我们是将etc下 hosts替换掉,推荐hosts: http://laod.cn/hosts/2015-google...host ...

  2. js学习对象创建

    Object.extend = function(destination, source) {for (var property in source) {    destination[propert ...

  3. [Codeforces137C]History(排序,水题)

    题目链接:http://codeforces.com/contest/137/problem/C 题意:给n对数,分别是一个事件的起始和终止时间.问被有几个事件被其他事件包含. 思路:先排序,按照起始 ...

  4. openfire中mysql的前期设置

    使用openfire的时候如果需要使用自己的mysql数据库,需要提前进行设置,下面将记录下,基本的设置过程. 一.前期准备工作: 1.先下载两个工具一个是mysql数据库还有一个是SQLyog(可以 ...

  5. Mybatis的if test字符串比较问题

    1. Mybatis判断字符串是否为空的变态写法 <if test="bussSceneIsNull =='0'.toString() "> <![CDATA[ ...

  6. MemSQL start[c]up Round 2 - online version(DP)

    只有小写字母 那>=2600的直接找单字母串长度大于等于100的就可以了 <2600 的dp找最长回文串 #include <iostream> #include<cst ...

  7. 1176. Hyperchannels(欧拉回路)

    1176 给定一有向图 求其反图的欧拉回路 路径输反了 一直WA.. #include <iostream> #include<cstdio> #include<cstr ...

  8. struct TABLE_SHARE

    struct TABLE_SHARE { TABLE_SHARE() {} /* Remove gcc warning */ /** Category of this table. */ TABLE_ ...

  9. MyBatis 实践 -动态SQL/关联查询

    MyBatis 实践 标签: Java与存储 动态SQL 动态SQL提供了对SQL语句的灵活操作,通过表达式进行判断,对SQL进行拼接/组装. if 对查询条件进行判断,如果输入参数不为空才进行查询条 ...

  10. I.MX6 Android netperf

    /***************************************************************************** * I.MX6 Android netpe ...