zoj 3762 Pan's Labyrinth

程吕恭
2023-12-01
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.


Author:  ZHU, Jiale

Source: ZOJ Monthly, March 2014



在n个点中找一个高最大的三角形,输出高


比赛时A的莫名其妙,对于每个点找出距离他最远的点,在枚举第三个点....这能证明么?还是数据弱了?还是我猜对了?


PS:

这种做法已经被否定了,当时能AC,纯属数据弱了,详情请戳Here !!!


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;

#define eps 1e-8

struct Point{
    double x,y;
}p[505];

inline double xmulti(const Point p1, const Point p2, const Point p0)
{
    return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
}

int n;

inline double dis(Point a,Point b){
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int pos[505];
double L[505];
vector<int>v[505];

int main(){
   // freopen("1.txt","r",stdin);
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        memset(pos,-1,sizeof(pos));
        memset(L,0,sizeof(L));
        for(int i=0;i<n;i++){
            v[i].clear();
        }
        for(int i=0;i<n;i++){
            double Min=0.0;
            int id=-1;
            for(int j=0;j<n;j++){
                double l=dis(p[i],p[j]);
                if(i==j || l<=eps) continue;
                if(Min<l){
                    Min=l;
                    id=j;
                }
            }
            if(id==-1) continue;
            for(int j=0;j<n;j++){
                double l=dis(p[i],p[j]);
                if(fabs(Min-l)<=eps){
                    v[i].push_back(j);
                }
            }
            L[i]=Min;
        }
        double ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<v[i].size();j++){
                int x=v[i][j];
                for(int k=0;k<n;k++){
                    if(k==x || k==i) continue;
                    double area=xmulti(p[i],p[x],p[k]);
                    double l1=dis(p[x],p[k]);
                   if(l1<=eps) continue;
                   double l2=dis(p[i],p[k]);
                    if(l2<=eps) continue;
                    if(fabs(area)/2.0<=eps) continue;
                    ans=max(ans,fabs(area)/sqrt(L[i]));
                    ans=max(ans,fabs(area)/sqrt(l1));
                    ans=max(ans,fabs(area)/sqrt(l2));
                }
            }
        }
        printf("%.8lf\n",ans);
    }
}


 类似资料:

相关阅读

相关文章

相关问答