zoj3762(几何...大概)

地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3762

Pan's Labyrinth

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

Ofelia is chased by her evil stepfather, and now she finds herself lost in a labyrinth. She needs your help to run away from her tragic family.

There's a huge metal door standing in front of the exit of the labyrinth. There are n dots on the metal door. Pan (the god of the labyrinth) asks Ofelia to find out a triangle which has the largest height. The triangle's three vertexes must be the dots on the door, and its area must be positive. Ofelia should tell Pan the triangle's height so Pan will let Ofelia go.

Input

There are multiple cases (About 100 cases). For each case, the first line contains an integer n (3<=n<=500). In the next n lines, each line contains two real number x[i]y[i] (0<=x[i], y[i]<=10000) which indicates each dot's coordinate. There is no two dots in the same coordinate. The answers are strictly greater than 0.

Output

For each test case, output one line with the maximum triangle height. Any solution with a relative or absolute error of at most 1e-6 will be accepted.

Sample Input
6
0.000 4.000
2.000 4.000
1.000 0.000
1.000 8.000
0.900 7.000
1.100 7.000
7
6967.54555 3457.71200
3.52325 1273.85912
7755.35733 9812.97643
753.00303 2124.70937
7896.71246 8877.78054
5832.77264 5213.70478
4629.38110 8159.01498

Sample Output
7.00000
8940.96643

Hint
In case 1. Choose the  dot 3, 5, 6  to make up a triangle, and this triangle has the largest height 7.000. In case 2. We choose dot 2, 3, 5.

题意:选任意三个点组成三角形,求出这些三角形中的最大高。

思路:看了下别人的想法,选一个点,找出距离他最远的点,再枚举第三个点,然后计算最大高。我觉得应该是找距离他最近的点才对,因为对于一个三角形,其面积是固定的,因此最短的边对应最长的高,但是提交了是WA。

代码:

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL __int64
#define Max 0xfffffff
struct point{
    double x,y;
}pp[510];
double lenth(point x,point y,point z){  //求点z到直线xy的距离
    if(x.x==y.x) return fabs(z.x-x.x);
    double a=(x.y-y.y)/(x.x-y.x);
    double b=x.y-a*x.x;
    double ans=fabs(a*z.x-z.y+b)/sqrt(a*a+1);
    return ans;
}
double juli(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
    int n;
    while(scanf("%d",&n)>0){
        for(int i=0;i<n;i++)
            scanf("%lf%lf",&pp[i].x,&pp[i].y);
        double maxx=0;
        for(int i=0,h;i<n;i++){
            double minn=0;
            for(int j=0;j<n;j++){
                if(j==i) continue;
                double k=juli(pp[i],pp[j]);
                if(minn<k){
                    minn=k;
                    h=j;
                }
            }
            for(int j=0;j<n;j++){
                if(j==i||j==h) continue;
                maxx=max(maxx,lenth(pp[i],pp[j],pp[h]));
                maxx=max(maxx,lenth(pp[i],pp[h],pp[j]));
                maxx=max(maxx,lenth(pp[j],pp[h],pp[i]));
            }
        }
        printf("%.5lf\n",maxx);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值