给出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(求三角形的最大高)的更多相关文章

  1. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  2. TZOJ 2519 Regetni(N个点求三角形面积为整数总数)

    描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...

  3. HDU 2036 叉乘求三角形面积

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  4. poj 1090:The Circumference of the Circle(计算几何,求三角形外心)

    The Circumference of the Circle Time Limit: 2 Seconds      Memory Limit: 65536 KB To calculate the c ...

  5. hdu 2105:The Center of Gravity(计算几何,求三角形重心)

    The Center of Gravity Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. hdu 4709:Herding(叉积求三角形面积+枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积

    Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...

  8. uva11178 Morley’s Theorem(求三角形的角三分线围成三角形的点)

    Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states that that the ...

  9. hdu4709求三角形面积

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

随机推荐

  1. C语言学习笔记 (007) - 数组指针和通过指针引用数组元素的方法总结

    1.数组指针:即指向数组的指针 那么, 如何声明一个数组指针呢? ]; /*括号是必须写的,不然就是指针数组:10是数组的大小*/ 拓展:有指针类型元素的数组称为指针数组. 2.通过指针引用数组元素的 ...

  2. socket编程及API简介

    什么是TCP/IP.UDP? TCP/IP(Transmission Control Protocol/Internet Protocol)即传输控制协议/网间协议,是一个工业标准的协议集,它是为广域 ...

  3. Linux安装ElasticSearch-2.2.0

    1.下载ElasticSearch-2.2.0安装包 https://www.elastic.co/downloads/elasticsearch 2.安装ElasticSearch-2.2.0 rp ...

  4. 【Linux】进程优先级、进程nice值和%nice

    用top或者ps命令会输出PRI/PR.NI.%ni/%nice这三种指标值,这些到底是什么东西?先给出大概的解释如下: PRI :进程优先权,代表这个进程可被执行的优先级,其值越小,优先级就越高,越 ...

  5. Oracle 12C -- native left outer join的加强

    在11g中SQL> select count(*)  2    from emp a, dept b, bonus c  3   where a.deptno(+) = b.deptno  4  ...

  6. MFC中无标题栏窗口的移动

    原文链接: http://blog.sina.com.cn/s/blog_6288219501015dwa.html   移动标准窗口是通过用鼠标单击窗口标题条来实现的,但对于没有标题条的窗口,就需要 ...

  7. 跟我学SharePoint 2013视频培训课程——删除恢复、文档离线工作(11)

    课程简介 第11天,怎样在SharePoint 2013中删除.恢复文档.文档离线工作. 视频 SharePoint 2013 交流群 41032413

  8. linux 压缩和解压命令

    Linux下的压缩解压缩命令详解及实例 实例:压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip == ...

  9. jota-time 练习

    public static void main(String[] args) { LocalDate now = new LocalDate(); //输出形式为yyyy-MM-dd System.o ...

  10. update document in mongodb using java -摘自网络

    update document in mongodb using java: Mongodb driver provides functionality to update document in m ...