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

Posted stiles

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 -1;
        double s = (a+b+c)/2.0;
        double s1 = c*c/4;
        double s2 = sqrt(s*(s-a)*(s-b)*(s-c));
        return s1+s2;
}
int main(){
  //freopen("input.txt","r",stdin);
  double a = 0, b = 0;
  cin >> a; cin >> b;
  double c = 0;
  //uble s1 = 0, s2 = 0;
  double max = 0;
  //the range of c is [0 a+b]
  double l = 0, r = a+b;
  double m,mm;
  double mv, mmv;
  while(l + EPS < r)
  {
        m = (r-l)/2 + l;
        mm = (r-m)/2 + m;
        mv = cal_area(a,b,m);
        //printf("%f
", 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
",mv, mmv, mv > mmv ? mv : mmv);

  return 0;
}

 

以上是关于1874 football game(三分法and method to compute the area of trianngle)的主要内容,如果未能解决你的问题,请参考以下文章

D. Innokenty and a Football League

三分法(洛谷3382 模板三分法)

三分法

模板三分法

CodeForces578 C. Weakness and Poorness

CodeForces - 754B Ilya and tic-tac-toe game