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. 用C语言实现Ping程序功能---转

    ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具.ping命令的工作原理是:向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文一模一样地传回给发送者,这 ...

  2. Golang教程:goroutine协程

    在上一篇中,我们讨论了并发,以及并发和并行的区别.在这篇教程中我们将讨论在Go中如何通过Go协程实现并发. 什么是协程 Go协程(Goroutine)是与其他函数或方法同时运行的函数或方法.可以认为G ...

  3. T-SQL语句创建表

    USE E_Market          --指定当前所操作的数据库 GO CREATE TABLE 表名 ( BID int identity (1,1)NOT NULL, BNAME varch ...

  4. Why Isn't curr_items Decreasing When Items Expire?

    Why Isn't curr_items Decreasing When Items Expire?

  5. 数据结构(四)--- 红黑树(RedBlock-Tree)

      文章图片来自邓俊辉老师课件 先提几个问题去思考学习本文 : 红黑树和2-4树(B-Tree)很像,那么它存在的动机又是什么呢 插入和删除操作的逻辑又是怎么样的,时间和空间复杂度可以达到怎么样 和 ...

  6. 微信小程序整理

    目录 开发环境 目录结构 WXML组件 WXSS 数据绑定 条件渲染 列表渲染 模版 事件 引用 路由传参 API 实例TodoList 1.开发环境 开发工具下载(https://mp.weixin ...

  7. Flash流媒体服务器软件

    所谓流媒体技术,是指将连续的影像和声音信息经过压缩处理后放在网站服务器上,让用户能够一边下载一边观看.收听(即所谓的“在线欣赏”),而不需要等整个压缩文件下载到自己的机器上才可以欣赏的网络传输技术.目 ...

  8. Spring学习笔记:面向切面编程AOP(Aspect Oriented Programming)

    一.面向切面编程AOP 目标:让我们可以“专心做事”,避免繁杂重复的功能编码 原理:将复杂的需求分解出不同方面,将公共功能集中解决 *****所谓面向切面编程,是一种通过预编译方式和运行期动态代理实现 ...

  9. Linux必会必知

    一.前言 Linux作为一个开源系统,被极客极力推崇,作为程序员不来了解一下,那就亏了 Linux是一种自由和开放源代码的类UNIX操作系统.该操作系统的内核由林纳斯·托瓦兹在1991年10月5日首次 ...

  10. img图片加载失败默认图片

    <img :src="item.goods_pic" onerror="javascript:this.src='../static/images/default. ...