Codeforces Round #358 (Div. 2) E. Alyona and Triangles 随机化
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的图)
证明也比较简单,这里略掉。
这个怎么做呢?经典题: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 随机化的更多相关文章
- Codeforces Round #358 (Div. 2) D. Alyona and Strings dp
D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree 水题
C. Alyona and the Tree 题目连接: http://www.codeforces.com/contest/682/problem/C Description Alyona deci ...
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers 水题
A. Alyona and Numbers 题目连接: http://www.codeforces.com/contest/682/problem/A Description After finish ...
- Codeforces Round #358 (Div. 2)B. Alyona and Mex
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp
题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes input ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #358 (Div. 2)——C. Alyona and the Tree(树的DFS+逆向思维)
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree
C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...
随机推荐
- JDOM生成XML文档的一般方法
由于DOM提供的生成XML的方法不够直观,而且要用到各种繁琐的注解,鉴于此可借助第三方库-----JDOM生成XML文档.具体操作方式如下: import java.io.FileOutputStre ...
- vue总结07 常用插件
插件 开发插件 插件通常会为 Vue 添加全局功能.插件的范围没有限制——一般有下面几种: 添加全局方法或者属性,如: vue-custom-element 添加全局资源:指令/过滤器/过渡等,如 v ...
- Python2和Python3同时安装到Windows
上月已经把Python2安装好了,安装目录和及其下的Scripts也在安装时添加到了环境变量PATH中,可以使用python命令执行程序. 安装包:python-2.7.14.amd64.msi(没有 ...
- centos7连接阿里云长时间连接不上
一.手动修改网卡配置 手上有几台centos7的linux,当连接阿里云的ecs服务器时候长时间连接不上,最后失败的问题. 使用 -vvv参数到如下语句就卡着不动了 ssh -vvv XXX.XXX. ...
- makefile特殊符号介绍
http://blog.chinaunix.net/uid-20564848-id-217918.html makefile下$(wildcard $^),$^,$@,$?,$<,$(@D),$ ...
- P1986 元旦晚会
一道可以用各种各样的办法做的(水)题 在这里就介绍两种做法 题意: 自己看看吧,很明显的意思,就是求前i个人最少有多少个话筒. 解法1:差分约束 设\(dis[i]\)表示前\(i\)个人最少有多少个 ...
- Kubernetes之YAML文件
一.YAML 基础 YAML是专门用来写配置文件的语言,非常简洁和强大,使用比json更方便.它实质上是一种通用的数据串行化格式.后文会说明定义YAML文件创建Pod和创建Deployment. YA ...
- Ubuntu 搭建ELK
一.简介 官网地址:https://www.elastic.co/cn/ 官网权威指南:https://www.elastic.co/guide/cn/elasticsearch/guide/curr ...
- ***四种参数传递的形式——URL,超链接,js,form表单
什么时候用GET, 查,删 什么时候用POST,增,改 (特列:登陆用Post,因为不能让用户名和密码显示在URL上) 4种get传参方式 <html xmlns="http:// ...
- vmstat详解
一.前言 很显然从名字中我们就可以知道vmstat是一个查看虚拟内存(Virtual Memory)使用状况的工具,但是怎样通过vmstat来发现系统中的瓶颈呢?在回答这个问题前,还是让我们回顾一下L ...