CodeForces 682E Alyona and Triangles (计算几何)
Alyona and Triangles
题目连接:
http://acm.hust.edu.cn/vjudge/contest/121333#problem/J
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
题意:
给出n个点,任意三个点组成的三角形面积不超过S;
构造一个大三角形覆盖上述所有n个点,并且面积不超过4S;
题解:
先找出最大的三角形;
再根据性质往三边拓展三个相同的三角形,面积即不超过4S;
找最大三角形:不停遍历n个点加入三角形点集合,可以证明复杂度不超过O(n^2);
(图盗用自@qscqesze同学~)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define double LL
#define eps 1e-8
#define maxn 5100
#define mod 1000000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
struct Point{
double x,y;
Point(){}
Point(double tx,double ty) {x=tx;y=ty;}
}p[maxn];;
double xmul(Point p0,Point p1,Point p2)
{return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}
double triangle_area(Point a,Point b,Point c) {
return abs(xmul(a,b,c));
}
int main(void)
{
//IN;
int n; LL S;
while(scanf("%d %I64d", &n,&S) != EOF)
{
for(int i=1; i<=n; i++)
scanf("%I64d %I64d", &p[i].x,&p[i].y);
bool flag = 1;
int a=1, b=2, c=3;
double ans = triangle_area(p[a],p[b],p[c]);
while(flag) {
flag = 0;
for(int i=1; i<=n; i++) {
double tmp;
tmp = triangle_area(p[a],p[b],p[i]);
if(tmp > ans) {
ans = tmp; c = i; flag = 1;
}
tmp = triangle_area(p[a],p[i],p[c]);
if(tmp > ans) {
ans = tmp; b = i; flag = 1;
}
tmp = triangle_area(p[i],p[b],p[c]);
if(tmp > ans) {
ans = tmp; a = i; flag = 1;
}
}
}
cout << p[a].x+p[b].x-p[c].x << ' ' << p[b].y+p[a].y-p[c].y << endl;
cout << p[a].x+p[c].x-p[b].x << ' ' << p[c].y+p[a].y-p[b].y << endl;
cout << p[c].x+p[b].x-p[a].x << ' ' << p[b].y+p[c].y-p[a].y << endl;
}
return 0;
}
CodeForces 682E Alyona and Triangles (计算几何)的更多相关文章
- 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 E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 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 ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...
- cf682E Alyona and Triangles
You are given n points with integer coordinates on the plane. Points are given in a way such that th ...
- Codeforces 1119E Pavel and Triangles (贪心)
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...
- codeforces 682C Alyona and the Tree(DFS)
题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...
随机推荐
- js学习对象创建
Object.extend = function(destination, source) {for (var property in source) { destination[propert ...
- Java注解实践
Java注解实践 标签 : Java基础 注解对代码的语意没有直接影响, 他们只负责提供信息给相关的程序使用. 注解永远不会改变被注解代码的含义, 但可以通过工具对被注解的代码进行特殊处理. JDK ...
- 關於NPOI的一點補充和示例
最近看到很多人分享NPOI的用法. 但是很多都不是完整示例或者並沒有實戰效果. 剛好最近有個VB.NET的項目有升級原有的oledb select sheet$的做法. 很明顯,NPOI有更好的穩定性 ...
- LA 2402 (枚举) Fishnet
题意: 正方形四个边界上分别有n个点,将其划分为(n+1)2个四边形,求四边形面积的最大值. 分析: 因为n的规模很小,所以可以二重循环枚举求最大值. 求直线(a, 0) (b, 0) 和直线(0, ...
- HDU 1272 小希的迷宫 (水题)
题意: 其实就是让你判断一个图是否为树,要求不能有孤立的点(没有这中情况),且只能有1个连通图,且边数+1=点数,且每个点都有边(不可能只有1个点出现). 思路: 有可能出现连续的4个0,也就是有测试 ...
- H.264学习笔记之一(层次结构,NAL,SPS)
一 H.264句法 1.1元素分层结构 H.264编码器输出的Bit流中,每个Bit都隶属于某个句法元素.句法元素被组织成有层次的结构,分别描述各个层次的信息. 图1 H.264分层结构由五层组成,分 ...
- 如何在Android开发中让你的代码更有效率
最近看了Google IO 2012年的一个视频,名字叫做Doing More With Less: Being a Good Android Citizen,主要是讲如何用少少的几句代码来改善And ...
- 【转】android布局属性详解
LinearLayout布局: 线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的.在这个界面中,我们应用了一个 LinearLayout的布局,它是垂直向下扩展的 ,所以创建的布局XML ...
- Android Scrollview 内部组件android:layout_height="fill_parent"无效的解决办法
Found the solution myself in the end. The problem was not with the LinearLayout, but with the Scrol ...
- 【Android】以SimpleAdapter做适配器的ListView和GridView
SimpleAdapter介绍 SimpleAdapter是一个简单的适配器,可以将静态数据映射到XML文件中定义好的视图. 构造函数 public SimpleAdapter (Context co ...