zoj 3762(求三角形的最大高)
给出n个点,要你找到一个三角形,它的高是最长的。
思路:暴力超时了,是用先找出n个点与其他点的最长边,再枚举顶点过的.......具体证明不知道.....
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define eps 1e-8
struct point
{
double x;
double y;
};
//点到直线的最短距离
//bool vist[500][500][500];
point intersection(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
}
point ptoline(point p,point l1,point l2)
{
point t=p;
t.x+=l1.y-l2.y;
t.y+=l2.x-l1.x;
return intersection(p,t,l1,l2);
}
double juli(point a,point b)
{
return (sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
double str[505][2];
int main()
{
int n;
while(scanf("%d",&n)>0)
{
//memset(vist,false,sizeof(vist));
for(int i=0; i<n; i++)
scanf("%lf%lf",&str[i][0],&str[i][1]);
double maxn=0;
point a,b,c;
point sp[1000][2];
int cnt=0;
for(int i=0; i<n; i++)
{
a.x=str[i][0];
a.y=str[i][1];
double zd=0;
for(int j=0; j<n; j++)
{
if(i==j) continue;
b.x=str[j][0];
b.y=str[j][1];
double tmp=juli(a,b);
if(tmp>zd)
{
zd=tmp;
sp[cnt][0]=a;
sp[cnt][1]=b;
}
}
cnt++;
}
for(int i=0; i<n; i++)
{
a.x=str[i][0];
a.y=str[i][1];
for(int j=0; j<cnt; j++)
{
b=sp[j][0];
c=sp[j][1];
point d=ptoline(a,b,c);
maxn=max(maxn,juli(d,a));
d=ptoline(b,a,c);
maxn=max(maxn,juli(d,b));
d=ptoline(c,a,b);
maxn=max(maxn,juli(d,c));
}
}
printf("%.5lf\n",maxn);
}
return 0;
}
zoj 3762(求三角形的最大高)的更多相关文章
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- TZOJ 2519 Regetni(N个点求三角形面积为整数总数)
描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...
- HDU 2036 叉乘求三角形面积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- poj 1090:The Circumference of the Circle(计算几何,求三角形外心)
The Circumference of the Circle Time Limit: 2 Seconds Memory Limit: 65536 KB To calculate the c ...
- hdu 2105:The Center of Gravity(计算几何,求三角形重心)
The Center of Gravity Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积
Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...
- uva11178 Morley’s Theorem(求三角形的角三分线围成三角形的点)
Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states that that the ...
- hdu4709求三角形面积
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
随机推荐
- HDU 4301 Divide Chocolate (DP + 递推)
Divide Chocolate Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 收缩sqlserver事务日志
若要允许 DBCC SHRINKFILE 命令收缩文件,首先需要通过将数据库恢复模式设置为 SIMPLE 来截断该文件. 示例,收缩数据库abce的事务日志 USE abce; GO -- Trunc ...
- API设计原则
译序 Qt的设计水准在业界很有口碑,一致.易于掌握和强大的API是Qt最著名的优点之一.此文既是Qt官网上的API设计指导准则,也是Qt在API设计上的实践总结.虽然Qt用的是C++,但其中设计原则和 ...
- 【转】TeXmacs:一个真正“所见即所得”的排版系统
TeXmacs:一个真正“所见即所得”的排版系统 好久没有推荐过自己喜欢的软件了,现在推荐一款我在美国做数学作业的私家法宝:TeXmacs.我恐怕不可能跟以前那么有闲心写个长篇的 TeXmacs 说明 ...
- STM8在IAR中Option Byte配置
转http://www.stmcu.org/module/forum/thread-607140-1-1.html 近期帮客户调试STM8的程序使用到OptionByte配置,在网上查询几乎都是介绍如 ...
- Django基于正则表达式的URL(2)
Django基于正则表达式的URL(2) 1. 关于正则的说明 url(r'^detail-(\d+)-(\d+).html',views.detail), 当客户端输入 127.0.0.1:8000 ...
- 怎么安装预装的win8三星笔记本改win7再装Ubuntu问题[zz]
随着科技的高速发展,人们对电脑的要求越来越高,对电脑系统的要求亦是,那些电脑自带的系统,很多时候已经无法满足人们的需求了,而为了满足自己的需求,人们往往会为电脑改装新系统,而本文要和大家一起分享的话题 ...
- JAVA classpath jar问题[zz]
classpath问题可以说是所有初学者头疼的问题,偶也一样. 1) classpath的作用: 它的作用就事让java找到你所要执行,或你拥有的类. 2) classpath的设置: 设置cla ...
- Maven .m2\repository\jdk\tools\1.7 missing
在pom.xml文件中加入: <dependency> <groupId>jdk.tools</groupId> <artifactId>jdk.too ...
- C#中 如何处理 JSON中的特殊字符
public static String StringToJson(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0 ...