给出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. Linux下mysql的远程连接(转)

    转载:http://www.cnblogs.com/fnlingnzb-learner/p/5830661.html 如果Mysql是按上篇的方法进行安装和设置的话,那进行远程连接就会稍微简单一点.我 ...

  2. fedora下安装运行keil uVision 4 (MDK v4.7)

    先准备好mdk4.73.exe和和谐文件. 1.安装 wine 1.7 添加ppa sudo add-apt-repository ppa:ubuntu-wine/ppa      安装wine 1. ...

  3. 【HTML】 向网页<Title></Title>中插入图片以及跑马灯

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style typ ...

  4. 使用Cordova搭建Andoid和iOS开发环境

    最近在了解cordova  ,下面的分享出来  大家可以看看,  我 有空也按照这个写写demo 1.下载node.js,进行安装 https://nodejs.org/en/ 2.安装cordova ...

  5. numpy 基于现有数据创建ndarray(from existing data)

    1 numpy.array array(object[, dtype=None, copy=True, order='K', subok=False, ndmin=0]) 2 numpy.asarra ...

  6. golang学习笔记 ---命名

    Go语言中的函数名.变量名.常量名.类型名.语句标号和包名等所有的命名,都遵循一个简单的命名规则:一个名字必须以一个字母(Unicode字母)或下划线开头,后面可以跟任意数量的字母.数字或下划线.大写 ...

  7. 探讨android更新UI的几种方法

    作为IT新手,总以为只要有时间,有精力,什么东西都能做出来.这种念头我也有过,但很快就熄灭了,因为现实是残酷的,就算一开始的时间和精力非常充足,也会随着项目的推进而逐步消磨殆尽.我们会发现,自己越来越 ...

  8. sqlserver使用存储过程发送http请求

    本文主要向大家介绍了SQLServer数据库访问发送Http请求,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助. -- 通用读取获取数据存储过程 --开启Sql Serve ...

  9. Android Developers:向其它应用发送用户

    Android的一个非常重要的功能是,应用程序基于它要执行的一个“动作”想其它应用程序发送用户的能力.例如,如果你的应用程序要显示一个地图,你没有在你的应用程序中创建显示地图的Activity.相反, ...

  10. 温故而知新 phpstudy 设置 nginx 代理

    nginx.conif 找到 server 关键字配置 server { listen ; server_name localhost; #charset koi8-r; #access_log lo ...