1874 football game(三分法and method to compute the area of trianngle)

FInd the max area.

1. 三分法

2. NAN (not comparable with number)

http://acm.timus.ru/problem.aspx?space=1&num=1874

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS 1e-9
//1874 to calculate the max area
//divide quardnage into two areas //helper function to cal the area
double cal_area(double a, double b, double c)
{
//check if theree exists triangle, otherwise, it will rturn nan, which is not comparable
if(c + a <= b || c + b <=a || a+b <=c) return -;
double s = (a+b+c)/2.0;
double s1 = c*c/;
double s2 = sqrt(s*(s-a)*(s-b)*(s-c));
return s1+s2;
}
int main(){
//freopen("input.txt","r",stdin);
double a = , b = ;
cin >> a; cin >> b;
double c = ;
//uble s1 = 0, s2 = 0;
double max = ;
//the range of c is [0 a+b]
double l = , r = a+b;
double m,mm;
double mv, mmv;
while(l + EPS < r)
{
m = (r-l)/ + l;
mm = (r-m)/ + m;
mv = cal_area(a,b,m);
//printf("%f\n", mv);
mmv = cal_area(a, b, mm);
//find first construct area
if(mv <= mmv) l = m;// edge case if mv == mmv(move to bigger one tot get bigger c)
else r = mm;
}
printf("%.7f\n",mv, mmv, mv > mmv ? mv : mmv); return ;
}
上一篇:openstack(Pike 版)集群部署(五)--- Neutron 部署


下一篇:bzoj 1202 并查集