Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化

时间:2022-09-03 12:37:35

E. Alyona and Triangles

题目连接:

http://codeforces.com/contest/682/problem/E

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

Hint

题意

给你n个点,保证覆盖的面积不超过S。

你需要找到一个面积小于4S的三角形,使得这个三角形包含了所有的点。

题解:

有一个结论,需要猜一下。

就是我其实就是找到这个n个点,中选择三个点组成的最大三角形。

找到这个三角形之后,通过旋转和放大之后,就可以得到我要的答案了。

如图:(来自Quailty的图)

Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化

证明也比较简单,这里略掉。

这个怎么做呢?经典题:http://www.spoj.com/problems/MTRIAREA/

其实随机化也可以,但是我不知道随机化是否能被卡掉,因为这道题要求并不是最优的……

代码

#include<bits/stdc++.h>
using namespace std; #define x first
#define y second
typedef pair<long long,long long> node;
long long cross(node a,node b,node c)
{
return abs((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x));
}
vector<node>P;
int n;
long long s;
int main()
{
cin>>n>>s;
for(int i=1;i<=n;i++)
{
node p;
scanf("%lld%lld",&p.x,&p.y);
P.push_back(p);
}
sort(P.begin(),P.end());
P.erase(unique(P.begin(),P.end()),P.end());
node a,b,c;
a=P[0],b=P[1],c=P[2];
long long ans = cross(a,b,c);
int flag = 1;
while(flag)
{
flag = 0;
random_shuffle(P.begin(),P.end());
for(int i=0;i<P.size();i++)
{
long long tmp = cross(P[i],b,c);
if(tmp>ans)
{
ans=tmp;
a=P[i];
flag=1;
}
}
for(int i=0;i<P.size();i++)
{
long long tmp = cross(a,P[i],c);
if(tmp>ans)
{
ans=tmp;
b=P[i];
flag=1;
}
}
for(int i=0;i<P.size();i++)
{
long long tmp = cross(a,b,P[i]);
if(tmp>ans)
{
ans=tmp;
c=P[i];
flag=1;
}
}
}
cout<<a.x+b.x-c.x<<" "<<a.y+b.y-c.y<<endl;
cout<<a.x+c.x-b.x<<" "<<a.y+c.y-b.y<<endl;
cout<<b.x+c.x-a.x<<" "<<b.y+c.y-a.y<<endl;
}

Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化的更多相关文章

  1. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; D&period; Alyona and Strings dp

    D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...

  2. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; C&period; Alyona and the Tree 水题

    C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...

  3. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; A&period; Alyona and Numbers 水题

    A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...

  4. Codeforces Round &num;358 &lpar;Div&period; 2&rpar;B&period; Alyona and Mex

    B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; D&period; Alyona and Strings 字符串dp

    题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes input ...

  6. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; C&period; Alyona and the Tree dfs

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Codeforces Round &num;358 &lpar;Div&period; 2&rpar;——C&period; Alyona and the Tree(树的DFS&plus;逆向思维)

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; C&period; Alyona and the Tree

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; B&period; Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

随机推荐

  1. iOS之隐藏键盘的方式

    一.//触摸空白处隐藏键盘 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [_feedBackTextView r ...

  2. 跟着百度学PHP&lbrack;4&rsqb;OOP面对对象编程-6-封装性private

    所谓封装顾名思义,如同箱子般给封装起来.结合前面的来说就是对属性或者方法,封装后的方法或属性只能有类内部进行调用.外部调用不了. 封装性的好处: 1.信息隐藏 2.http://www.cnblogs ...

  3. 关于如何来构造一个String类

    今天帮着一位大二的学弟写了一个String的类,后来一想这个技术点,也许不是什么难点,但是还是简单的记录一些吧! 为那些还在路上爬行的行者,剖析一些基本的实现..... 内容写的过于简单,没有涉及到其 ...

  4. 反射中通过class标记来获取字段及方法

    //这是通过class标记获取字段的代码 Field[] fields= classzz.getDeclaredFields(); //获取该class标记的表名代码,必须为,getSimpleNam ...

  5. PHPnow升级PHP 5&period;4与Mysql 5&period;5

    本文转载自:https://www.dadclab.com/archives/5928.jiecao 折腾开始 1.安装一下VC9的运行库,下载地址:https://www.microsoft.com ...

  6. 你能识别这些科技公司的真假logo吗?

    快告诉我,不止我一个眼瞎~

  7. 代码bug

    1.webstorm ide未配置basePath本地会加入根路径 2.点击一次就销毁可以给标签设置一个值data-val="0" 某个函数只执行一次的方法,或者也可以考虑绑用on ...

  8. Laravel中间件

    先谈一谈中间件的使用场景,比如路由转到一张页面,我们需要记录用户的cookie,或者检测用户的访问权限,这些操作如果全写在控制器里是不合适的,因为随着业务的扩充,控制器里的业务逻辑会越来越臃肿,难以维 ...

  9. Appium 常用方法总结 &lpar;python 版&rpar;

    1.app后台运行 driver.background_app(5) 2.锁屏 driver.lock(5) 3.隐藏键盘 driver.hide_keyboard() 4.启动一个app或者在当前a ...

  10. DL&lowbar;WITH&lowbar;PY系统学习(第2章)

    ​ 本节提示: 1.第一个dl例子: 2.tensor和tensor操作: 3.DL如何通过逆向传播和梯度下降达到学习目的. 2.1 输入数据集的格式 ,*,))) network.add(layer ...