PKU 2079 Triangle
来源:互联网 发布:js 读取图片格式 编辑:程序博客网 时间:2024/06/05 04:45
Triangle
Description
Given n distinct points on a plane, your task is to findthe triangle that have the maximum area, whose vertices are from the givenpoints.
平面上有n 个点,找出一个三角形有最大的面积,三角形的顶点来自给定的n个点。
Input
The input consists of several test cases. The first lineof each test case contains an integer n, indicating the number of points on theplane. Each of the following n lines contains two integer xi and yi, indicatingthe ith points. The last line of the input is an integer −1, indicating the endof input, which should not be processed. You may assume that 1 <= n <=50000 and −104 <= xi, yi <= 104 for all i= 1 . . . n.
有多组测试数据,每组测试数据的第一行包括一个整数n,描述平面上有n个点。接下来的n行,每行包括两个整数xi,yi,表示第i个点。最后一行是整数-1,表示输入结束。-1不需要处理。你可以假设: 1 <= n <= 50000 并且 −104 <= xi, yi <= 104 (i = 1 . . . n).
Output
For each test case, print a line containing the maximumarea, which contains two digits after the decimal point. You may assume that thereis always an answer which is greater than zero.
每组测试数据输出一行,包含一个数,最大的面积maxare并且保留有两个小数点,你可以假设结果都是大于0的。
Sample Input
3
3 4
2 6
2 7
5
2 6
3 9
2 0
8 0
6 5
-1
Sample Output
0.50
27.00
解题思路:
具有最大面积的三角形的三个顶点必定在凸包上。
证明:
1、 假设三个点都不在凸包上设为abc。
设ab为底边,c点到边的距离看做高hc,那么一定可以在凸包上找到一点p,p到ab的距离hp大于hc。所以至少有一个点在凸包上。
2、 假设只有一个点在凸包上。设Abc(A在凸包上)
假设Ab为底边,c到Ab的距离hc,那么一定可以在凸包上找到一点p,使p到Ab的距离hp大于hc,所以至少有两个点在凸包上。
3、 假设只有两个点在凸包上,设Abc(AB在凸包上)
设底边AB,c到AB的距离hc,一定可以在凸包上找到一点p,使p点到AB的距离hp大于hc,故三个点必须都在凸包上。
第一步:
nlogn的Jarvis算法求凸包。
第二步:
1、 有以上证明故可以枚举凸包上的点,时间复杂度为,即O()(n为凸包上的点的个数)。
2、 可以枚举一个底边:然后用旋转卡壳的方法求距离该底边的最远距离的点。O()。
旋转卡壳过程描述:
用p[m]表示有m个顶点的凸包。以顶点p[i]为例:
1、 找到距离底边p[i],p[i+1]最远的点p[k];
2、 设距离底边p[i]p[j-1]最远的点为p[t];
对于距离底边p[i]p[j]最远的点为p[r];
s1=crossleft(p[i],p[j],p[t]);
s2=crossleft(p[i],p[j],p[t+1]);
if(s1>s2)
p[r]=p[t];
else
p[r]=p[t+1];
- PKU 2079 Triangle
- pku 1163 Triangle
- pku 1163 The Triangle
- Pku 1163 the Triangle
- PKU-1163 The Triangle
- pku 1163 The Triangle(DP)
- PKU ACM 1163-The Triangle
- pku 3137 Parkside's Triangle
- ACM pku 1163 The Triangle
- Pku acm 1163 the Triangle
- pku 1673 EXOCENTER OF A TRIANGLE
- 入门DP pku 1163 The Triangle
- PKU 1673 EXOCENTER OF A TRIANGLE 三角形的垂心
- Pku acm 1163 the Triangle 动态规划题目解题报告(一)
- POJ 2079 Triangle
- POJ 2079 Triangle
- poj 2079 Triangle
- POJ 2079 Triangle 题解
- 正式搬家
- android AIDL
- Tomcat+Apache配置集群详解(2)
- 一个三维的数据存到数据库
- 积分
- PKU 2079 Triangle
- shell 之空格
- java正则表达式
- CentOS 下,设置IP DNS Hostname
- java中List的用法和实例详解
- win2003开启硬件加速
- 【Android游戏开发十九】(必看篇)SurfaceView运行机制详解—剖析Back与Home按键及切入后台等异常处理!
- Tomcat+Apache配置集群详解(1)
- 用VNC XP远程连接CENTOS