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. 运行Android应用时提示ADB是否存在于指定路径问题

    打开eclipse,选择指定的Android应用工程并Run,提示: [2014-06-28 11:32:26 - LinearLayout] The connectionto adb is down ...

  2. 宏btr_pcur_open_on_user_rec

    参考http://wqtn22.iteye.com/blog/1820436 http://blog.jcole.us/2013/01/10/btree-index-structures-in-inn ...

  3. WinScp上传和下载

    不多说,贴代码,看不懂得可以留言.需要引入WinSCP public class WebWinScp { //远程上传路径 private SessionOptions sessionOptions ...

  4. BZOJ3850: ZCC Loves Codefires

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题解:类似于国王游戏,推一下相邻两个元素交换的条件然后排个序就可以了. 代码: #inc ...

  5. asp.net读excle的数据类型不统一取出空值问题

    如果表格里某列全是数字或是字符没问题,但如果混合了全是数字和部分字符就会有部分读取为空连接EXCEL方式如下 string strConn = "Provider=Microsoft.Jet ...

  6. UVA 11354 Bond(最小瓶颈路+倍增)

    题意:问图上任意两点(u,v)之间的路径上,所经过的最大边权最小为多少? 求最小瓶颈路,既是求最小生成树.因为要处理多组询问,所以需要用倍增加速. 先处理出最小生成树,prim的时间复杂度为O(n*n ...

  7. codeforces 334A - Candy Bags

    忘了是偶数了,在纸上画奇数画了半天... #include<cstdio> #include<cstring> #include<cstdlib> #include ...

  8. 【转】visual studio 2012进行C语言开发[图文]

    原文网址:http://blog.csdn.net/chengyafei0104/article/details/9826025 现在大家计算机大概都脱离XP了,so,之前蛮多可以用的编译器,可能放在 ...

  9. Java 7爆最新漏洞,10年前的攻击手法仍有效

    英文原文:New Reflection API affected by a known 10+ years old attack 据 SECLISTS 透露,他们发现新的 Reflection API ...

  10. GCC 编译优化指南

    转自: http://www.jinbuguo.com/linux/optimize_guide.html GCC 编译优化指南 作者:金步国[www.jinbuguo.com] 版权声明 本文作者是 ...