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 ;
}
1874 football game(三分法and method to compute the area of trianngle)的更多相关文章
- ural 1874 Football Goal
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...
- Dalvik虚拟机java方法执行流程和Method结构体分析
Method结构体是啥? 在Dalvik虚拟机内部,每个Java方法都有一个对应的Method结构体,虚拟机根据此结构体获取方法的所有信息. Method结构体是怎样定义的? 此结构体在不同的andr ...
- 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 ...
- ArrowLayer : A coustom layer animation
Since my other answer (animating two levels of masks) has some graphics glitches, I decided to try r ...
- matlab函数_连通区域
1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二值图像BW中面积小于P的对象,默认情况下使用8邻域.算法:(1)De ...
- matlab函数bwareaopen的详解
matlab函数_连通区域 1. matlab函数bwareaopen──删除小面积对象格式:BW2 = bwareaopen(BW,P,conn)作用:删除二值图像BW中面积小于P的对象,默认情况下 ...
- Kafka - protocol
http://kafka.apache.org/protocol 具体的协议看原文, Preliminaries Network Kafka uses a binary protocol ov ...
- 实现多项式的JAVA类
p = coef[i] + (x * p); } Poly ...
- [CareerCup] 9.5 Permutations 全排列
9.5 Write a method to compute all permutations of a string. LeetCode上的原题,请参加我之前的博客Permutations 全排列和P ...
随机推荐
- MySql的内置函数
MySQL的内置函数不但可以在SELECT查询语句中应用,同样也可以在INSERT.UPDATE和DELECT等语句中应用.例如,在INSERT添加语句中,应用日期时间函数获取系统的当前时间,并且将其 ...
- IT自由职业者的第一个月(下)——为什么放弃5年嵌入式驱动开发转到WEB开发?
如果单从兴趣来看,其实我对Linux内核,Android中间件的兴趣要高于WEB,何况还有这么多年的经验积累,何必从头探索一个新的技术方向呢? 这里面原因是很多的,最核心的大概是以下4 ...
- Firebird hash join
Firebird 现可支持哈希连接(hash join),各中大型数据库,哈希连接已成为平常,相对于循环嵌套连接(Nested Loop Join),在数据量较大的情况下,哈希连接性能较好. 由于 F ...
- bnu Game 博弈。
Game Time Limit: 10000ms Case Time Limit: 10000ms Memory Limit: 65536KB 64-bit integer IO format: ...
- LeetCode Palidrome Number
class Solution { public: bool isPalindrome(int x) { ) return false; ; int t = x; ; ) { pow *= ; cnt+ ...
- python文件修改 核心5步,函数实现修改任意文件内容
文件修改 核心5步1.以读的模式打开原文件,产生句柄f12.以写的模式打开一个新文件,产生句柄f23.读取原文件的内容并将原文件需要替换的内容修改写入到新文件4.删除原文件5.把新文件重名了成原文件 ...
- ccf-201709-2 公共钥匙盒
问题描述 有一个学校的老师共用N个教室,按照规定,所有的钥匙都必须放在公共钥匙盒里,老师不能带钥匙回家.每次老师上课前,都从公共钥匙盒里找到自己上课的教室的钥匙去开门,上完课后,再将钥匙放回到钥匙盒中 ...
- Mysql与web之间的数据、查询等个问题
Mysql与web之间的数据.查询等个问题 在自己写的一个jsp主页连接数据库出现的各种问题,写记下来与大家分享,共勉.最后附jdbc代码. ---DanlV Error 1---错误代码: java ...
- Python基础-I/O模型
一.I/O模型 IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接 ...
- C++类继承--基类析构函数加上Virtual
下面的内容要说明两个问题:1. 基类的析构函数为什么要加上Virtual--防止内存泄露 1. 基类虚构函数无virtual,派生类无法析构,会导致内存泄露 #include <stdio.h& ...