2005 TCO Online Round 1 - RectangleError

简介: RectangleError  Problem's Link Problem Statement      You want to draw a rectangle on a piece of paper.

 

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 = 0;

       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 0;
}
/*

*/
目录
相关文章
|
JavaScript 数据库
uni-app的多环境部署配置
分享下如何对uni-app项目进行多环境打包部署改造
2469 0
|
7月前
|
关系型数据库 MySQL OLAP
无缝集成 MySQL,解锁秒级 OLAP 分析性能极限,完成任务可领取三合一数据线!
通过 AnalyticDB MySQL 版、DMS、DTS 和 RDS MySQL 版协同工作,解决大规模业务数据统计难题,参与活动完成任务即可领取三合一数据线(限量200个),还有机会抽取蓝牙音箱大奖!
|
关系型数据库 Go 数据库
【Go语言专栏】Go语言中的数据库迁移与版本控制
【4月更文挑战第30天】本文介绍了Go语言中的数据库迁移和版本控制。针对数据库迁移,文章提到了使用Flyway和Liquibase两个工具。通过示例展示了如何在Go中集成这两个工具进行数据库结构的修改,以适应业务变化。而对于版本控制,文章以Git为例,说明了如何利用Git进行源代码和配置文件的管理,确保代码一致性与可追溯性。
532 0
|
12月前
|
算法 数据可视化 计算机视觉
Python中医学图像处理常用的库
在Python中,医学图像处理常用的库包括:ITK(及其简化版SimpleITK)、3D Slicer、Pydicom、Nibabel、MedPy、OpenCV、Pillow和Scikit-Image。这些库分别擅长图像分割、配准、处理DICOM和NIfTI格式文件、图像增强及基础图像处理等任务。选择合适的库需根据具体需求和项目要求。
453 0
|
JavaScript 前端开发 Go
Github 2024-08-12 开源项目周报 Top14
本周Github Trendings共有14个项目上榜,按开发语言汇总如下:Python项目7个,TypeScript项目5个,C项目2个,JavaScript项目2个,Go和Batchfile项目各1个。其中亮点包括开发者职业成长指南、Windows激活工具、ComfyUI图形界面、AFFiNE知识库、易采集可视化爬虫等项目,涵盖多种实用工具和开源平台。
612 1
|
11月前
|
存储 大数据
究竟什么是大数据,大数据具体应该怎么定义
【10月更文挑战第29天】大数据是指那些传统资料处理技术无法应对的海量数字信息,包括文本、音视频、电子邮件等多类型数据。它涉及数据的获取、分析、存储与传输,需借助专门的技术手段。大数据分析能够帮助企业洞察消费者行为、预测市场趋势,从而实现业务增长。随着数字化进程加快,高效管理与利用大数据成为企业面临的重大挑战。
374 2
|
关系型数据库 Serverless 分布式数据库
ICDE’24 | 中国企业首获最佳论文,详解PolarDB Serverless如何在0.5秒内实现跨机迁移
数据库领域顶会 ICDE 2024于5月13-17日在荷兰乌特勒支(Utrecht, Netherlands)举办。ICDE (The International Conference on Data Engineering) 与VLDB、SIGMOD被公认为是国际数据管理领域三大顶级学术会议,此次在荷兰召开的ICDE 2024大会,共吸引北京大学、清华大学、浙江大学、MIT、斯坦福等机构,以及谷歌、微软、阿里云、华为、字节等公司的近1000名人员参会,共同探讨AI、数据库、数据处理领域的前沿技术问题。
|
机器学习/深度学习 搜索推荐 算法
【再识C进阶2(下)】详细介绍指针的进阶——利用冒泡排序算法模拟实现qsort函数,以及一下习题和指针笔试题
【再识C进阶2(下)】详细介绍指针的进阶——利用冒泡排序算法模拟实现qsort函数,以及一下习题和指针笔试题
167 0
|
存储 消息中间件 运维
高可用架构和系统设计思想
本文从研发规范层面、应用服务层面、存储层面、产品层面、运维部署层面、异常应急层面这六大层面去剖析一个高可用的系统需要有哪些关键的设计和考虑
|
运维 小程序 API
社区每周丨支付宝小程序导航栏升级及人脸认证计费规则更新
社区每周丨支付宝小程序导航栏升级及人脸认证计费规则更新
369 0