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