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 ;
}

1874 football game(三分法and method to compute the area of trianngle)的更多相关文章

  1. ural 1874 Football Goal

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...

  2. Dalvik虚拟机java方法执行流程和Method结构体分析

    Method结构体是啥? 在Dalvik虚拟机内部,每个Java方法都有一个对应的Method结构体,虚拟机根据此结构体获取方法的所有信息. Method结构体是怎样定义的? 此结构体在不同的andr ...

  3. Method for browsing internet of things and apparatus using the same

    A method for browsing Internet of things (IoT) and an apparatus using the same are provided. In the ...

  4. ArrowLayer : A coustom layer animation

    Since my other answer (animating two levels of masks) has some graphics glitches, I decided to try r ...

  5. matlab函数_连通区域

    1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二值图像BW中面积小于P的对象,默认情况下使用8邻域.算法:(1)De ...

  6. matlab函数bwareaopen的详解

    matlab函数_连通区域 1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二值图像BW中面积小于P的对象,默认情况下 ...

  7. Kafka - protocol

    http://kafka.apache.org/protocol   具体的协议看原文,   Preliminaries Network Kafka uses a binary protocol ov ...

  8. 实现多项式的JAVA类

                                   p = coef[i] + (x * p);               }                           Poly ...

  9. [CareerCup] 9.5 Permutations 全排列

    9.5 Write a method to compute all permutations of a string. LeetCode上的原题,请参加我之前的博客Permutations 全排列和P ...

随机推荐

  1. 4、在Shell程序中的使用变量

    学习目标变量的赋值变量的访问变量的输入 12-4-1 变量的赋值在Shell编程中,所有的变量名都由字符串组成,并且不需要对变量进行声明.要赋值给一个变量,其格式如下:变量名=值.注意:等号(=)前后 ...

  2. shell -- 获取绝对路径

    readlink -f <file> readlink -m <file> 会把file的相对路径转化为绝对路径 几个选项的区别: -f, --canonicalize can ...

  3. html元素两种分类。替换元素和不可替换元素;块级元素和行内元素

    根据元素本身特点来分类: 替换元素替换元素根据其标签和属性来决定元素的具体显示内容.有<img><input><textarea><select>< ...

  4. C#把大写英文变成小写英文,把小写英文变成大写英文

    static void Main(string[] args) { string s;  // 声明一个变量,来接受用户输入的值. Console.WriteLine("请输入一个字符串:& ...

  5. 【转】XDocument简单入门

    1.什么是XML? 2.XDocument和XmlDocument的区别? 3.XDocument 4.XmlDocument 5.LINQ to XML 6.XML序列化与反序列化 因为这几天用到了 ...

  6. js实现栈

    栈是一种先进后出的特殊线性表结构,存储上分链式存储和顺序存储两种方式 链式存储: function LinkedStack() { let Node = function (ele) { this.e ...

  7. nodejs中引入art-template模板

    使用Webstorm创建nodejs express应用时,默认使用的是jade或者ejs模板,对于不习惯这两种模板语法的人来说确实不是很方便.没关系,这里我们使用art-template模板引擎,使 ...

  8. java 记录

    1.spring ide 的安装图解 https://blog.csdn.net/u012369373/article/details/55097380 2.ssm框架配置内容 http://www. ...

  9. javaweb之jsp标签

    1.JSP标签简介 JSP标签也称之为Jsp Action(JSP动作)元素,它用于在Jsp页面中提供业务逻辑功能,避免在JSP页面中直接编写java代码,造成jsp页面难以维护. 2.JSP常用标签 ...

  10. SZU3

    CodeForces 343A 这是第一题,像这种水题一定不要想复杂,思路不对立马换. 抓住串联和并联,可以用辗转相除法 #include <iostream> #include < ...