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 ...
随机推荐
- 查看Windows激活信息
使用 Windows + R组合快捷键打开运行命令框 1.运行: slmgr.vbs -dlv 可以查询到Win10的激活信息,包括:激活ID.安装ID.激活截止日期等信息. 2.运行: slmgr. ...
- Objective-C - NSString 和 NSDate 互相轉換
記錄一下在 Objective-C 由 NSString 轉換為 NSDate 或 NSDate 轉換為 NSString 的方法. 很簡單,使用 NSDateFormatter 就可以令 NSStr ...
- 快学UiAutomator UiDevice API 详解
一.按键使用 返回值 方法名 说明 boolean pressBack() 模拟短按返回back键 boolean pressDPadCenter() 模拟按轨迹球中点按键 boolean press ...
- PJSIP-iOS源码编译
官方文档https://trac.pjsip.org/repos/wiki/Getting-Started/iPhone 功能 在iPhone上可以实现的功能: 包含基于CoreAudio的音频设备, ...
- LeetCode || 递归 / 回溯
呜呜呜 递归好不想写qwq 求“所有情况”这种就递归 17. Letter Combinations of a Phone Number 题意:在九宫格上按数字,输出所有可能的字母组合 Input: ...
- IP数据包的校验和算法
1.算法思路: IP/ICMP/IGMP/TCP/UDP等协议的校验和算法都是相同的,算法如下: 在发送数据时,为了计算IP数据包的校验和.应该按如下步骤: (1)把IP数据包的校验和字段置为0: ( ...
- luogu2312 解方程 (数论,hash)
luogu2312 解方程 (数论,hash) 第一次外出学习讲过的题目,然后被讲课人的一番话惊呆了. 这个题,我想着当年全国只有十几个满分.....然后他又说了句我考场A这道题时,用了5个模数 确实 ...
- [LUOGU] P1880 [NOI1995]石子合并
题目描述 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...
- Idea 搭建Maven--web项目(MVC)
小编最近正在学习使用MVC框架,在搭建Maven的项目过程中,遇到了很多问题,上网搜了很多材料才找到答案,为了小编以后查起来方便,也为了向广大小伙伴分享,写了这部片博文,敬我昨天一天的学习结果! 步骤 ...
- Python赋值运算及流程控制
1. 内置函数 1> len:统计元素长度 str1 = 'wonderful' print(len(str1)) result: li = [,,] print(len(li)) result ...