cf682E 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
Note
要找个三角形把所有点都包在里面
画画图就会发现,只要在这些点中找个面积最大的三角形,然后对三条边都翻折过去变成一个4倍大的三角形就好了
面积最大的三角形找法有点迷……一开始就选123号点,然后每次尝试把一个点替换之后面积会不会变大
一直做到不再变大为止。
这玩意似乎有什么定理 可以证明2-stable point一定属于3-stable point?
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
LL n,k;
struct point{
LL x,y;
}p[];
int a,b,c;
point operator +(point a,point b){return (point){a.x+b.x,a.y+b.y};}
point operator -(point a,point b){return (point){a.x-b.x,a.y-b.y};}
inline LL calc(int a,int b,int c)
{
LL x1=p[c].x-p[a].x,y1=p[c].y-p[a].y,x2=p[b].x-p[a].x,y2=p[b].y-p[a].y;
LL ans=x1*y2-x2*y1;
if (ans<)ans=-ans;
return ans;
}
int main()
{
n=read();k=read();
for (int i=;i<=n;i++)p[i].x=read(),p[i].y=read();
a=;b=;c=;
bool refresh=;
while (!refresh)
{
refresh=;
for (int i=;i<=n;i++)
if (i!=a&&i!=b&&i!=c)
{
if (calc(a,b,c)<calc(i,b,c))a=i,refresh=;
else if (calc(a,b,c)<calc(a,i,c))b=i,refresh=;
else if (calc(a,b,c)<calc(a,b,i))c=i,refresh=;
}
}
point d=p[a]+p[b]-p[c],e=p[a]+p[c]-p[b],f=p[c]+p[b]-p[a];
printf("%lld %lld\n",d.x,d.y);
printf("%lld %lld\n",e.x,e.y);
printf("%lld %lld\n",f.x,f.y);
}
cf 682E
cf682E Alyona and Triangles的更多相关文章
- CodeForces 682E Alyona and Triangles (计算几何)
Alyona and Triangles 题目连接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/J Description You ar ...
- Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化
E. Alyona and Triangles 题目连接: http://codeforces.com/contest/682/problem/E Description You are given ...
- 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 ...
- Count the number of possible triangles
From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
- Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)
A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks f ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
随机推荐
- Linux SSH无密码login
一:ssh原理图为: 1.就是为了让两个linux机器之间使用ssh不需要用户名和密码.采用了数字签名RSA或者DSA来完成这个操作 2.模型分析 假设 A (192.168.20.59)为客户机器, ...
- lua_to_luac
#!/bin/sh `rm -rf allLua.zip` `mkdir ./tempScripts` `mkdir ./tempScripts/scripts` `cp -a ./scripts/ ...
- Servlet和JSP之标签文件学习
在上一篇文章中介绍了自定义标签的用法,接下来介绍标签文件的用法啦. tag file指令 tag file简介 用tag file的方式,无需编写标签处理类和标签库描述文件,也可以自定义标签.tag ...
- Django添加tinyMCE编辑器
tinymce的使用方法很简单,只需要在html页面中包含如下: <!-- Place inside the <head> of your HTML --> <scrip ...
- iOS上架问题解决
dns问题 http://iphone.91.com/tutorial/syjc/140509/21686339.html 网络问题 手机4g开wifi,上传提交多次 时间问题 东八区下午6点上架成功 ...
- 快学UIautomator之uiautomatorhelp使用
1.先下载uiautomatorhelp插件 2.把uiautomatorhelp.java包放到自己的项目中 3.项目中引入uiautomatorhelp插件 4.在项目中设置一个main方法,引入 ...
- word2vec 中的数学原理详解(二)预备知识
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/peghoty/article/details/37969635 https://blog.csdn. ...
- passive event 解决方法
为了让页面滚动的效果如丝般顺滑,从 chrome56 开始,在 window.document 和 body 上注册的 touchstart 和 touchmove 事件处理函数,会默认为是 pass ...
- 更改ubuntu的官方镜像源
我们自己安装的ubuntu通常默认镜像源是官方的,并不好用,因为网速以及限制比较多,所以为了使用方便,通常都会去更改一下默认的镜像源配置. 这里我们使用清华大学开源镜像软件站,https://mirr ...
- 七:MYSQL之常用操作符
前言: 运算符连接表达式中各个操作数,其作用是用来指明对操作数所进行的运算. 常见的运算有数学计算.比较运算.位运算及逻辑运算 一:算数运算符 用于各类数值运算.包括加(+).减(-).乘(*).除( ...