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 ...
随机推荐
- 【LinuxC】GCC编译C程序,关闭随机基址
1.编译.链接和运行程序 C代码示例: #include <stdio.h> #include <stdlib.h> int main() { printf("hel ...
- 18 - csv文件-ini文件处理
目录 1 CSV文件 1.1 手动生成一个csv文件 1.2 cvs模块 1.2.1 reader方法 1.2.2 writer方法 2 ini文件处理 2.1 configparser模块 2.2 ...
- Android Bander设计与实现 - 设计
Binder Android IPC Linux 内核 驱动 摘要 Binder是Android系统进程间通信(IPC)方式之一.Linux已经拥有管道,system V IPC,socket等IPC ...
- 乐视mysql面试题【转】
最近,朋友去乐视面试了mysql DBA,以下是我据整理的乐视mysql面试题答案,供大家参考 1. MYISAM和INNODB的不同?答:主要有以下几点区别: a)构造上的区别 MyIS ...
- 读书笔记 effective c++ Item 19 像设计类型(type)一样设计类
1. 你需要重视类的设计 c++同其他面向对象编程语言一样,定义了一个新的类就相当于定义了一个新的类型(type),因此作为一个c++开发人员,大量时间会被花费在扩张你的类型系统上面.这意味着你不仅仅 ...
- 01 Getting Started 开始
Getting Started 开始 Install the Go tools Test your installation Uninstalling Go Getting help Downlo ...
- 配置sql server 2000以允许远程访问
配置sql server 2000以允许远程访问适合故障:1. 用sql企业管理器能访问sql server 2000(因为它是采用命名管道(named pipes)方式进行方式),但用ado.net ...
- IdentityServer4揭秘---Consent(同意页面)
授权同意页面与登录一样首先要分析页面的需要什么模型元素后建立相关的模型类 界面的话就 记住选择 .按钮.RuturnUrl.以及选择的资源Scope /// <summary> /// ...
- 好久没有写过SQL了,今天写了一句select in留存
应同事要求,直接去接数据库的数据. 数据C里有一个name是查询的起始. 然后,B其实是一个多对多的中间表, 通过B查出id之后, 就可以在A里找到需要的数据了. select name from A ...
- mysqlsla 安装
tar -zxvf mysqlsla-2.03.tar.gz cd mysqlsla-2.03 perl Makefile.PLmake && make install BEGIN f ...