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;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5689483.html

CodeForces 682E Alyona and Triangles (计算几何)相关推荐

  1. Codeforces 1025F Disjoint Triangles (计算几何)

    题目链接 https://codeforces.com/contest/1025/problem/F 题解 一道挺有意思的计算几何题 qwq 关键在于注意到任何一对不相交的三角形之间,一定有 \(2\ ...

  2. Codeforces 739B Alyona and a tree (树上路径倍增及差分)

    题目链接 Alyona and a tree 弄了好几个小时终于Accepted了,之后发现这个题是Div1的. 比较考验我思维的一道好题. 首先,做一遍DFS预处理出t[i][j]和d[i][j]. ...

  3. uva 12426 Counting Triangles 计算几何

    题意:给一个凸多边形,求以凸多边形的顶点为顶点的三角形中,有多少个面积小于给定数值K? 思路:旋转卡壳+二分答案 时间复杂度:n^2logn 1 #include<iostream> 2 ...

  4. codeforces 849B Tell Your World(计算几何)

    题意: 给你一个直角坐标系,上面有n个点,问你能不能画两条不重合的平行线,使得每条平行线至少经过一个点,且所有的点都在其中一条平行线上. 思路: 提取前三个点,根据题目要求,这两条线其中一条必经过前三 ...

  5. CodeForces 739C Alyona and towers

    题目大意 给定一个长度为 n n的序列aa和 m m个操作,每个操作将[L,R][L,R]的元素加上 d d. 每次操作完后询问序列aa中最长的连续子序列满足 al<al+1<...< ...

  6. html img 坐标,Html img 标签

    Html img 标签 a标签点击跳转失效--IE6.7的奇葩bug 一般运用a标签包含img去实现点击图片跳转的功能,这是前端经常要用到的东西. 今天遇到个神奇的bug:如果在img上再包裹一层di ...

  7. CF1284E·New Year and Castle Construction

    初见安~这里是传送门:Codeforces 1284 E Sol 一眼计算几何,然后就不可做了[啪. 题意是这样的:平面上有n个点,问你存在多少组四个点围成的四边形[也可能是三角形]严格包围某个点的情 ...

  8. 杂题记录及简要题解(一)

    一些前几天做过的还不错的但是不是太想专门花一整篇博客的篇幅去写的题就简要地记录在这里. 说是简要题解,其实写得还是挺详细的.之后的杂题记录可能就会写得简略一点. CF1060E Sergey and ...

  9. visualstudio发布网站到服务器,VisualStudio2017 远程 调试 IIS 服务器 web网站

    准备使用 Office 365 中国版--邮箱迁移 微软产品一贯的作风是从来不缺文档和教程,Office 365也不例外.无论是最终用户还是企业IT管理员,都可参照Office 365使用指南顺利的开 ...

  10. java 当前日期前一天_java获取当前日期的前一天和后一天

    /** * 获得指定日期的前一天 * @param specifiedDay * @return * @throws Exception */ public static String getSpec ...

最新文章

  1. 解决Qt+OpenGL更换图像纹理的问题
  2. SpringMVC项目前台利用ajaxFileUpload传递图片后台接收
  3. [转]Creating Unit Tests for ASP.NET MVC Applications (C#)
  4. ADC和DAC常用技术术语
  5. linux adduser mysql,linux独享初始配置方法(ftp、apache、mysql)
  6. VMware vCenter Server6.5安装及群集配置介绍
  7. easyx 备忘录_报到?上课?我被自己的备忘录骗到了
  8. 如何用excel筛选相似内容_excel如何筛选出相同内容,excel怎么用公式筛选
  9. Git笔记(37) 替换
  10. [转]MVC+JQuery validate实现用户输入验证
  11. lightGBM用于排序(Learning to Rank )
  12. Android 手机 超级终端命令解析
  13. win7怎么把计算机图标下的箭头掉,电脑快捷方式图标箭头怎么去掉?Win7系统去掉快捷方式箭头的方法...
  14. Filco圣手二代键盘蓝牙连接方法
  15. 番茄钟怎么调_番茄时钟响铃提醒设置方法
  16. Vue - 实现信纸输入写作,类似写明信片时的一张背景图片 + 横格纸效果(信纸格子与文字自动对齐、支持自定义背景图、文字或横线大小与颜色,一切由您 DIY 自定义样式)纯CSS完成支持任何vue项目
  17. Zephyr Kernel 设备驱动和设备模型(一)
  18. 十年电影票房数据爬取与分析 | 免费数据教程
  19. centos8 安装mysql8(二)
  20. 快速过一遍计算机基础--操作系统—4.文件管理

热门文章

  1. Mac新手使用技巧,键盘键位分布和快捷键
  2. FxFactory 8 Pro for Mac(fcpx/ae/pr视觉特效插件包)
  3. 好用的markdown编辑工具Ulysses 25 for Mac
  4. Timemator for Mac(自动化计时管理软件)
  5. 苹果Mac更改备忘录默认字体的方法图解
  6. Mac版IntelliJ IDEA上手的一些必要设置
  7. 势差、高度、结构、做工、逆熵
  8. 【排错】exchange2013不能显示所有OU
  9. win7(64位)php5.5-Apache2.4-环境安装
  10. Mellanox infinoband RDMA SDP