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 ...
随机推荐
- jumpserver安装教程
centos7系统一步一步安装jumpserver 参照官方文档,查找了百度所有的文档,基本上都是按照官方的文档操作的 官方文档点我-> 安装jumpserver需注意: 1:网络环境要好,有的 ...
- MySQL 导入CSV数据
第一步 创建表结构 create table t1( key1 ), v1 ) ); 第二步 导入数据 load data local infile 'D:/t1.csv' into table t1 ...
- Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
在设置请求头的时候报这个Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPE ...
- 15 Defer, Panic, and Recover
Defer, Panic, and Recover 4 August 2010 Go has the usual mechanisms for control flow: if, for, switc ...
- 【web开发】web前端开发常用技术总结归纳
技术选型规范规范 • Vue版本:2.x • 前端路由:vue-route • 异步请求:Axios • 全局状态管理:VueX • css预处理器:sass/less • h5项目移动端适配规则:使 ...
- MySQL学习笔记:生成一个时间序列
今天遇到一个需求是生成以下表格的数据,一整天24小时,每秒一行数据. 寻找颇旧,找到另外两个实现的例子,暂且学习一翻.另一个见另外一篇. DAY) AS DATE FROM ( ) AS tmp, ( ...
- Python练手之爬虫
很久没更新博客了,最近自学Python,写个在百度上爬算法题题解的爬虫,第一次写爬虫..纯当练手 慢慢来.. #coding:utf-8 ''' Created on 2016年11月22日 @aut ...
- python中mock的使用
什么是mock? mock在翻译过来有模拟的意思.这里要介绍的mock是辅助单元测试的一个模块.它允许您用模拟对象替换您的系统的部分,并对它们已使用的方式进行断言. 在Python2.x 中 mock ...
- Hive(九)Hive 执行过程实例分析
一.Hive 执行过程概述 1.概述 (1) Hive 将 HQL 转换成一组操作符(Operator),比如 GroupByOperator, JoinOperator 等 (2)操作符 Opera ...
- 【LOJ】#2061. 「HAOI2016」放棋子
题解 水题,可惜要写高精度有点烦 一看障碍物的摆放方式和最后的答案没有关系,于是干脆不读了,直接二项式反演可以得到 设\(g_k\)为一种摆放方式恰好占了k个障碍物 \(f_k = \sum_{i = ...