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. 关于数据库NULL值的几个问题思考

    最近在写项目,拼接SQL时,发现好多关于NULL值的问题,现在把这些问题整理出来,以供日后参考. 对于Oracle数据库: 一.排序 Oracle对于null值的排序,有一个函数可以进行操作: 在默认 ...

  2. HTML5离线资源缓存简介

    cache manifest 示例 要使用离线资源缓存,开发者首先要提供一个 cache manifest 文件 它列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地 下面就是一个 c ...

  3. poj 2259 Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Descri ...

  4. Maven 常见知识点整理

    认识 Maven Maven 的作用? 1.添加第三方jar包 2.解决jar包之间的依赖关系 3.获取第三方jar包 4.将项目拆成多个工程模块 Maven 是什么? 是Apache软件基金会组织维 ...

  5. HDU 5691 ——Sitting in Line——————【状压动规】

    Sitting in Line Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Other ...

  6. GridView 基本使用

    项目中实例一 <asp:GridView ID="gvBatchReceive" runat="server" AutoGenerateColumns=& ...

  7. vue加载Element ui地址省市区插件-- element-china-area-data

    1.安装 npm install element-china-area-data -S 2.使用(引入) import { provinceAndCityData, regionData, provi ...

  8. JQuery extend()与工具方法、实例方法

    使用jQuery的时候会发现,jQuery中有的函数是这样使用的: $.get(); $.post(); $.getJSON(); 有些函数是这样使用的: $('div').css(); $('ul' ...

  9. ASP.NET MVC4 新手入门教程之一 ---1.介绍ASP.NET MVC4

    你会建造 您将实现一个简单的电影清单应用程序支持创建. 编辑. 搜索和清单数据库中的电影.下面是您将构建的应用程序的两个屏幕截图.它包括显示来自数据库的电影列表的网页: 应用程序还允许您添加. 编辑和 ...

  10. MySQL:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    解决方法: 修改密码:alter user 'root'@'localhost' identified by '123456'; mysql> use mysql; ERROR 1820 (HY ...