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 ...
随机推荐
- 我的ORM之十三 -- 性能参数
我的ORM索引 测试环境 台式机: 主板:映泰Z77 CPU:i5 3470(3.2GHz) 内存:DDR3 1600 8G(单条) 硬盘:创见 SSD 256G ORM从过程上,可以分两个大的部分: ...
- angular.js 例子
angular.js是一个前端的MVC框架,12年的时候曾近在一个portal平台的项目中使用过. 下面给出一个angular.js的典型例子,涵盖一些基础的知识点,用以复习备忘: <html ...
- 5天玩转C#并行和多线程编程 —— 第二天 并行集合和PLinq
5天玩转C#并行和多线程编程系列文章目录 5天玩转C#并行和多线程编程 —— 第一天 认识Parallel 5天玩转C#并行和多线程编程 —— 第二天 并行集合和PLinq 5天玩转C#并行和多线程编 ...
- 用手机访问本地环境的利器ngrok
我们在调试移动端页面,尤其是调试微信页面的时候,会遇到这样的情况,手机连着公司的wifi,开发环境(台式机)插着公司的网线,我们要用手机来访问开发环境下的页面.这个时候,如果网线和wifi是在同一个网 ...
- drag & resize元素的jQuery实现
有时项目中会遇到需要拖动元素.拖拽调整元素大小的需求.大部分时候都不想自己写一遍,因为已经有很多现成的例子了.例如jqueryui提供的drag和resize.但是仅仅是为了这么小一个功能就引入一个库 ...
- 剑英陪你玩转图形学(五)focus
很久没来和大家交流业务(zhuangbi)水平了,最近实在是很忙,报名了小游戏大赛,一点时间都抽不出,已经坑了. 今天抓紧时间和大家介绍一个小效果: 新手引导的时候,我们会需要一种全屏幕黑掉,只有一个 ...
- git rm–r folder fatal:pathspec "" did not match any files
问题描述: 某年某月某日,在查看git库的时候,发现文件的分布和文件夹的名字是极其不合理的,所以移动和重命名了某些文件. 在删除(git rm –r folder)一个空文件夹的时候,出现错误:fat ...
- JS实现无限分页加载——原理图解
由于网页的执行都是单线程的,在JS执行的过程中,页面会呈现阻塞状态.因此,如果JS处理的数据量过大,过程复杂,可能会造成页面的卡顿.传统的数据展现都以分页的形式,但是分页的效果并不好,需要用户手动点击 ...
- Java的概述以及语法
Java的语法分为标示符和数据类型 Java的概述: 一些手打的: long l = 12345; //隐式转换 int a = (int)121234567L; //强制转换 float f =12 ...
- Java基础,输入输出
package hanqi.test; import java.io.File; import java.io.IOException; public class Test02 { public st ...