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 ...
随机推荐
- Cobbler自动部署主机系统
Cobbler自动部署主机系统 简介: Cobbler由python语言开发,是对PXE和 Kickstart以及DHCP的封装.融合很多特性,提供了CLI和Web的管理形式.更加方便的实行网络安装. ...
- mytop安装,使用mytop监控MySQL性能
本文主要描述mytop安装,安装过程中可能出现的报错,以及使用mytop监控MySQL性能. 欢迎转载,请注明作者.出处. 作者:张正 blog:http://space.itpub.net/2635 ...
- idea上activiti插件的安装及使用
最近做的东西需要用到activiti,做个笔记 首先下载activti插件- actiBPM File - settings-plugins-Browse-Repositories 搜索 actiBP ...
- html5界面手机播放mp3
1把这段代码复制到htm5界面. <audio id="audio" src="2.mp3" style="opacity:0" pr ...
- System.ComponentModel.DataAnnotations.Schema 冲突
System.ComponentModel.DataAnnotations.Schema 冲突 Entity Framework 与 .net4.5 的 System.ComponentModel.D ...
- linux 下 pip 安装教程
方法一: 下载文件 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate 执行安装 python get-pip.py 这就 ...
- linux下配置tomcat集群的负载均衡
linux下配置tomcat集群的负载均衡 一.首先了解下与集群相关的几个概念集群:集群是一组协同工作的服务实体,用以提供比单一服务实体更具扩展性与可用性的服务平台.在客户端看来,一个集群就象是一个服 ...
- 如何获取 docker 容器(container)的 ip 地址(转)
1. 进入容器内部后 cat /etc/hosts 会显示自己以及(– link)软连接的容器IP 2.使用命令 docker inspect --format '{{ .NetworkSetting ...
- Maven:浅析依赖(dependency)关系中 scope 的含义(转)
在 Pom4 中,dependency 元素中引入了 scope 元素,这是一个很重要的属性.在Maven 项目中 Jar 包冲突.类型转换异常的很大原因是由于 scope 元素使用不当造成的. sc ...
- django http404 详解
[引子] 今天在看django的官方文档的时候看到get_object_or_404这个函数感觉比较奇怪.这个主要来自于它的功能,如果要查询的对象 存在那么就返回对象:如果对象不存在那么就要报404 ...