2005 TCO Online Round 1-rectangleerror

Source: Internet
Author: User
Tags hypot

Rectangleerror problem ' s Link

Problem Statement

want to draw a rectangle on a piece of paper. Unfortunately, you is not a perfect draftsman. The lines you make, although straight, does not always has the correct lengths. The top edge has a length in the inclusive range [Topmin,topmax], the left edge in the inclusive range [Leftmin,leftmax], an D The right edge in the inclusive range [Rightmin,rightmax]. Fortunately, the left, top and right edges is 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 of the bottom edge could be.

Definition

-Class: rectangleerror

-Method: bottomrange

-Parameters: double , double, doubles, doubles and double

-Returns: double

-method Signature: double Bottomrange (double topmin, double TopMax, double leftmin, double Leftmax, double rightmin, D Ouble Rightmax)

-(Be sure your method was public)

Notes

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

Constraints

-Each input would be between 5 and inclusive.

-Topmin is not being greater than TopMax.

-Leftmin is not being greater than Leftmax.

-Rightmin is not being greater than Rightmax.

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

Mean:

Given the length range of the top, left, and right sides of a rectangle, the maximum possible length and the minimum possible length of the bevel length of the left and right vertices of the connection are obtained.

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

*/

2005 TCO Online Round 1-rectangleerror

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.