RectangleError

Problem's Link

Problem Statement

You want to draw a rectangle on a piece of paper. Unfortunately, you are not a perfect draftsman. The lines you make, although straight, do not always have the correct lengths. The top edge has length in the inclusive range [topMin,topMax], the left edge in the inclusive range [leftMin,leftMax], and the right edge in the inclusive range [rightMin,rightMax]. Fortunately, the left, top and right edges are at right angles to each other and meet (where applicable) at their ends. The bottom edge is made by connecting the bottom end of the left edge to the bottom end of the right edge. Return the maximum length the bottom edge could be minus the minimum length the bottom edge could be.

Definition

-Class: RectangleError

-Method: bottomRange

-Parameters: double, double, double, double, double, double

-Returns: double

-Method signature: double bottomRange(double topMin, double topMax, double leftMin, double leftMax, double rightMin, double rightMax)

-(be sure your method is public)

Notes

- Your return value must have an absolute or relative error less than 1e-9.

Constraints

- Each input will be between 5 and 100 inclusive.

- topMin will not be greater than topMax.

- leftMin will not be greater than leftMax.

- rightMin will not be greater than rightMax.

----------------------------------------------------------------------------

Mean:

给定一个矩形的顶边、左边、右边的长度范围,求连接左边和右边下顶点的斜边长的最大可能长度与最小可能长度的差.

analyse:

Time complexity: O(1)

view code

#include <bits/stdc++.h>
using namespace std; class RectangleError
{
public:
double bottomRange(double topMin, double topMax, double leftMin, double leftMax, double rightMin, double rightMax)
{ double Max = max(hypot(topMax, leftMin-rightMax) , hypot(topMax, leftMax-rightMin)); double y;
if(rightMin >= leftMax)
y = rightMin - leftMax;
else if(leftMin >= rightMax)
y = rightMax - leftMin;
else
y = ; double Min = hypot(topMin, y);
return Max-Min;
}
}; int main()
{
double topMin,topMax,leftMin, leftMax, rightMin,rightMax;
while(cin>>topMin>>topMax>>leftMin>>leftMax>>rightMin>>rightMax)
{
RectangleError rectangleError;
double ans=rectangleError.bottomRange(topMin,topMax,leftMin,leftMax,rightMin,rightMax);
printf("%f\n",ans);
}
return ;
}
/* */

2005 TCO Online Round 1 - RectangleError的更多相关文章

  1. TCO 2014 Round 1C 概率DP

    TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover, ...

  2. TCO 2014 Round 1A

    顺利搞出  A B 两题,然后压线晋级了,手速场. A 题 , 求排列最小的,肯定从后往前来做,维护一个最小的set,只是第一个字母要特判一下. 1: #line 5 "EllysSorti ...

  3. TCO 2015 Round 1B DIV1 500 概率题

    [题意]现在有一些线索,每个线索被发现的概率p[i],如果线索i被知道,那么其他线索也可能会被知道,用vector<string> c给出,c[i][j]='Y'表示知道i这个线索,j这个 ...

  4. [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...

  5. TCO 2015 Round 2A DIV1

    ModModMod 傻逼数论 题意: 这是一道卖萌的题..给你一个取模序列$m$,令$f(x)=(\cdots (x\ mod\ m[0])\ mod m[1])\mod m[2]\cdots $,问 ...

  6. TCO 2016 Round 1B

    problem 250 Problem Statement Vasa likes to construct sequences of numbers. If you tell him a positi ...

  7. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  8. Dynamic Programming: From novice to advanced

    作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...

  9. TCO14 2C L2: CliqueGraph,graph theory, clique

    称号:http://community.topcoder.com/stat?c=problem_statement&pm=13251&rd=16017 參考:http://apps.t ...

随机推荐

  1. dojo/dom-style样式操作学习笔记

    基础总结 一个元素的样式信息由三个来源根据层叠规则确定.三个来源分别是: 由DOM元素style特性设置的内联样式 由style元素中嵌入的样式规则 由link元素引入的外部样式表 元素的样式 任何支 ...

  2. [ZigBee] 14、Zigbee无线通信前奏——BasicRF 简单无线点对点传输协议

    本工程不带zigbee协议栈,作为过渡 实验现象: 一个EB2530(终端A)定义为发射模块,另一个EB2530(终端B)定义为接收模块. 按EB2530(终端A)上的按键,无线控制另一个EB2530 ...

  3. 5、CC2541芯片中级教程-OSAL操作系统(PWM+看门狗)

    本文根据一周CC2541笔记汇总得来—— 适合概览和知识快速索引—— 全部链接: 中级教程-OSAL操作系统\OSAL操作系统-实验01 OSAL初探 [插入]SourceInsight-工程建立方法 ...

  4. React Native02-开始运行 Android篇

    1. 开始运行 1)用命令进入到新建的文件目录下,比如HelloWorld,再输入 react-native start: 在等待一段时间后,我们看到最后面有个地址,说明已经运行成功了. 我们输入地址 ...

  5. Permission is only granted to system apps

    原文地址http://jingyan.baidu.com/article/9113f81b2e7a8c2b3314c711.html

  6. Linux初学 - 文件夹及文件操作

    创建文件夹 mkdir 移动文件夹 mv dir1 dir2 复制文件夹 cp 删除文件夹 rm 创建文件 touch 编辑文件内容 vi /vim 查看文件内容 cat 追加文件内容 echo 复制 ...

  7. 利用奇异值分解(SVD)简化数据

    特征值与特征向量 下面这部分内容摘自:强大的矩阵奇异值分解(SVD)及其应用 特征值分解和奇异值分解在机器学习领域都是属于满地可见的方法.两者有着很紧密的关系,在接下来会谈到,特征值分解和奇异值分解的 ...

  8. 让我们一起写出更有效的CSharp代码吧,少年们!

    周末空闲,选读了一下一本很不错的C#语言使用的书,特此记载下便于对项目代码进行重构和优化时查看. Standing On Shoulders of Giants,附上思维导图,其中标记的颜色越深表示在 ...

  9. stackView的隐藏与显示注意事项

    1.想要通过变换stackView的y值来让stackView显现/隐藏,同时让其中的button能点击响应,得用topCons 2.导航栏的tinBar要设置为非透明状态

  10. WPF自定义控件与样式(14)-轻量MVVM模式实践

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. MVVM是WPF中一个非 ...