标签:style color io os ar for strong sp c
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.
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.
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.
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
7.00000 8940.96643
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.
#include<iostream> #include<cstdio> #include<string> #include<algorithm> # include<cmath> using namespace std; const int maxn=500+5; struct point { double x,y; point(double x=0,double y=0):x(x),y(y) {} }; typedef point Vector; double cross(Vector A, Vector B) { return A.x*B.y-A.y*B.x; } double Dot(Vector A, Vector B) { return A.x*B.x+A.y*B.y; } double Length(Vector A) { return sqrt(Dot(A,A)); } double distanc(point A, point B) { return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)); } Vector operator -(Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); //被重载坑了一上午。 } double DistanceToLine(point p,point A,point B) { Vector u=B-A,v=p-A; return fabs(cross(u,v))/Length(u); } /*double dist(point a,point b,point c) { if(b.x!=a.x) { double k=(b.y-a.y)/(b.x-a.x); return fabs((c.y-a.y)-k*(c.x-a.x))/sqrt(1+k*k); } else return fabs(c.x-a.x); }*/ point num[maxn]; int i,j,k; int main() { /*#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif*/ int n; while(cin>>n) { int k; double high; high=0.0; for(i=0;i<n;i++) scanf("%lf%lf",&num[i].x,&num[i].y); for(i=0;i<n;i++) { double mmax=0.0; for(j=0;j<n;j++) { if(j==i) continue; if(distanc(num[i],num[j])>mmax) { k=j; mmax=distanc(num[i],num[j]); } } for(j=0;j<n;j++) { if(i==j||j==k) continue; high=max(high,DistanceToLine(num[i],num[j],num[k])); high=max(high,DistanceToLine(num[j],num[k],num[i])); high=max(high,DistanceToLine(num[k],num[j],num[i])); } } printf("%0.6f\n",high); } return 0; }
标签:style color io os ar for strong sp c
原文地址:http://blog.csdn.net/u013514722/article/details/39778359