2005 TCO Online Round 1 - RectangleError
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的更多相关文章
- TCO 2014 Round 1C 概率DP
TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover, ...
- TCO 2014 Round 1A
顺利搞出 A B 两题,然后压线晋级了,手速场. A 题 , 求排列最小的,肯定从后往前来做,维护一个最小的set,只是第一个字母要特判一下. 1: #line 5 "EllysSorti ...
- TCO 2015 Round 1B DIV1 500 概率题
[题意]现在有一些线索,每个线索被发现的概率p[i],如果线索i被知道,那么其他线索也可能会被知道,用vector<string> c给出,c[i][j]='Y'表示知道i这个线索,j这个 ...
- [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...
- TCO 2015 Round 2A DIV1
ModModMod 傻逼数论 题意: 这是一道卖萌的题..给你一个取模序列$m$,令$f(x)=(\cdots (x\ mod\ m[0])\ mod m[1])\mod m[2]\cdots $,问 ...
- TCO 2016 Round 1B
problem 250 Problem Statement Vasa likes to construct sequences of numbers. If you tell him a positi ...
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- Dynamic Programming: From novice to advanced
作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...
- TCO14 2C L2: CliqueGraph,graph theory, clique
称号:http://community.topcoder.com/stat?c=problem_statement&pm=13251&rd=16017 參考:http://apps.t ...
随机推荐
- 熟用js中的Date
js中的Date类型是使用UTC(国际协调时间)自1970年1月1日午夜(零时)开始,经过的毫秒数来保存日期. 1. 创建日期对象 ---> 获得当前日期和时间 var now = new ...
- [stm32] STM32的通用定时器TIMx系统了解
通用定时器(TIMx) 一.TIMx简介 二.TIMx主要功能 三.TIMx功能描述 3.1 时基单元 3.2 计数器模式 3.3 时钟选择 3.4 捕获/比较通道 3.5 输入捕获模式 3.6 PW ...
- rsync permission denied created directories have no permissions
这个问题坑了好几天 最后被此贴解决 http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directo ...
- C#将dll打包到程序中
最近比较懒,加上内容也不多就懒得排版了,字放大了,看起来应该方便一点 直接进入主题 先来看一个栗子,假设现在有一个第三方dll namespace TestLibrary1 { public clas ...
- [翻译]AKKA笔记 - ACTOR MESSAGING - REQUEST AND RESPONSE -3
上次我们看Actor消息机制,我们看到开火-忘记型消息发出(意思是我们只要发个消息给Actor但是不期望有响应). 技术上来讲, 我们发消息给Actors就是要它的副作用. 这就是这么设计的.除了不响 ...
- knh
市场调研,分析—— 决定是否创业 不要再极度的沉默无言.宅.无存在感,无趣,难熬..
- Redis数据库的安装配置方
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/100.html?1455869650 redis 是一个高性能的key-v ...
- Atitti css transition Animation differ区别
Atitti css transition Animation differ区别 1.1. transition的优点在于简单易用,但是它有几个很大的局限. 1 1.2. js 动态改变 st ...
- html_01之基础标签
1.嵌套规则:①行内不能嵌套块:②p不能嵌套块:③非布局元素不要嵌套div: 2.标准属性:①id:定义元素唯一名称(a.布局时用:b.JS用):②title:鼠标移入时提示的文字:③class:定义 ...
- 解决h5的video标签,android、ipad客户端播放正常,iphone客户端无法播放
在做html5时插入一个视频播放标签video后,测试时android.ipad客户端播放正常,唯独iphone自带浏览器无法播放. 解决办法: 判断用户所使用客户端访问h5页面时是iphone时,点 ...