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. [HDOJ4738]Caocao's Bridges(双联通分量,割边,tarjan)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 给一张无向图,每一条边都有权值.找一条割边,使得删掉这条边双连通分量数量增加,求权值最小那条. ...

  2. Fragment 和 FragmentActivity的使用(二)

      今天继续完成剩下的学习部分,现在项目很多地方使用viewpager来提供滑动,今天记录学习viewpager配合fragment的显示,增加一个CallLogsFragment配合之前SMSLis ...

  3. 3D开发--CopperCube

    CopperCube的常用接口,以及如何用javascript语言控制场景中的人物动作,或者获取任务的位置等信息

  4. HTTPS通信机制

    概述 使用HTTP协议进行通信时,由于传输的是明文所以很容易遭到窃听,就算是加密过的信息也容易在传输中遭受到篡改,因此需要在HTTP协议基础上添加加密处理,认证处理等,有了这些处理机制的HTTP成为H ...

  5. [转]SQL、LINQ、Lambda

    原文链接:http://www.cnblogs.com/mr-hero/p/3532631.html SQL   LinqToSql   Lambda 1. 查询Student表中的所有记录的Snam ...

  6. noip2005提高组题解

    05年的题目绝对是自2000年以来难度最大的.后三题的难度系数分别为0.2.0.2.0.3,而前面几年的题目中每年最多只出现一道难度系数为0.2的题目,其难度可见一斑. 强烈推荐这个 PPT,每道题都 ...

  7. BUFFER CACHE之主要的等待事件

    原因:资源紧张,等待其释放. 原因的原因:1. lgwr和DBWn进程写太慢:2. Buffer和latch不可用 原因的原因的原因:全表扫描.library cache latches数太多等. 视 ...

  8. MySQL基础之第7章 索引

    第7章 索引 MySQL中,所有的数据类型都可以被索引,包括普通索引,唯一性索引,全文索引,单列索引,多列索引和空间索引等. 7.1.索引简介 7.1.1.索引的含义和特点 BTREE索引,HASH索 ...

  9. View.VISIBLE、INVISIBLE、GONE的区别

    android中UI应用的开发中经常会使用view.setVisibility()来设置控件的可见性,其中该函数有3个可选值,他们有着不同的含义: View.VISIBLE--->可见View. ...

  10. winfrom dataGridView 自定义分页实现

    Winfrom 基本处于忘光的阶段.先需要做个winfrom 的软件.然后自己扩展了DataGridView带分页的控件.废话不多说 上图先   现在一步步实现其效果. 1.添加用户控件 上图即可知道 ...