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. PowerShell笔记

    教程: http://www.pstips.net/powershell-online-tutorials/ http://www.3fwork.com/a113/ 1. 查看成员 $MyInvoca ...

  2. 阿里巴巴-OS事业群-OS手机事业部-系统服务部门招聘Java开发工程师,有意者请进来

    我是阿里巴巴-OS事业群-OS手机事业部-系统服务部的开发工程师,正在招聘Java开发工程师. 以下是职位描述: 岗位名称:Java开发工程师 招聘人数:5人 生效日期:2014-03-12 结束日期 ...

  3. 一天一小段js代码(no.4)

    最近在看网上的前端笔试题,借鉴别人的自己来试一下: 题目: 写一段脚本,实现:当页面上任意一个链接被点击的时候,alert出这个链接在页面上的顺序号,如第一个链接则alert(1), 依次类推. 有一 ...

  4. 如何为编程爱好者设计一款好玩的智能硬件(三)——该选什么样的MCU呢?

    一.我的构想:如何为编程爱好者设计一款好玩的智能硬件(一)——即插即用.积木化.功能重组的智能硬件模块构想 二.别人家的孩子:如何为编程爱好者设计一款好玩的智能硬件(二)——别人是如何设计硬件积木的! ...

  5. 使用protractor操作页面元素

    Protractor是为Angular JS应用量身打造的端到端测试框架.它可以真实的驱动浏览器,自动完成对web应用的测试.Protractor驱动浏览器使用的是WebDriver标准,所以使用起来 ...

  6. MVVM架构~knockoutjs系列之数组的$index和$data

    返回目录 已经写了很多knockoutjs的文章了,今天在review代码时,忽然看到一个问题,在knockout环境下,如何遍历一个简单的数组?对于遍历对象组件的数组来说,很容易,直接foreach ...

  7. Atitit  图像处理底色变红的解决

    Atitit  图像处理底色变红的解决 1.1. 原因  ImageIO  bug ,alpha通道应该在保存jpg的时候排除1 1.2. 解决,自己移除alpha通道即可1 2. Image sav ...

  8. CI Weekly #2 | 如何优化开发流程,实现项目持续集成?

    原文首发于 flow.ci Blog >> 链接,转载请联系:) CI Weekly 围绕『 软件工程效率提升』 进行一系列技术内容分享,包括国内外持续集成.持续交付,持续部署.自动化测试 ...

  9. 使用JSExcelXML.js导出Excel模板

      github地址:https://github.com/464884492/JSExcelXml 业务系统显示效果图 导出模板图 功能描述    世间万物总是相生相克,既然我们的客户要求有导出Ex ...

  10. draggable属性设置元素是否可拖动。

    设置标签属性draggable="true"将一个标签内的元素拖动到另外一个标签进行显示: <!DOCTYPE HTML> <html> <head& ...