Submit | All submissions | Best solutions | Back to list |
MAXLN - THE MAX LINES |
In this problem you will be given a half-circle. The half-circle’s radius is r. You can take any point A on the half-circle and draw 2 lines from the point to the two sides of the diameter(AB and AC). Let the sum of square of one line’s length and the other line’s length is s
Like in the figure s = AB2 + AC. And BC = 2r.
Now given r you have to find the maximum value of s. That is you have to find point A such that AB2 + AC is maximum.
Input
First line of the test case will be the number of test case T (1 <= T <= 1000). Then T lines follows. On each line you will find a integer number r (1 <= r <= 1000000); each representing the radius of the half-circle.
Output
For each input line, print a line containing "Case I: ", where I is the test case number and the maximum value of s. Print 2 digit after decimal (Errors should be less then .01).Example
Sample Input: 1 1 Sample Output: Case 1: 4.25
Added by: | Muhammad Ridowan |
Date: | 2011-03-28 |
Time limit: | 1s-1.679s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own Problem(used for CSE,University of Dhaka, Newbies Contest) |
hide comments
|
||||||||||||||
2018-04-05 18:13:27
AC in one go...... with 4 lines of code:) |
||||||||||||||
2018-04-02 17:31:08
Use double as the data type and make sure to type cast your solution when printing |
||||||||||||||
2018-03-30 07:16:32
Use long long int _/\_ |
||||||||||||||
2018-02-23 14:18:51
simple differentiation and use setprecision() ....only maths |
||||||||||||||
2018-02-09 17:24:19 Divyam Shah
@Nani the value of roots is not imaginary, for AC=0.5 we get "AC^2 - AC = -0.25". |
||||||||||||||
2018-01-03 10:55:20
4 lines of code...easy 1 :) |
||||||||||||||
2017-12-27 19:37:56 nani
There seems to be some loophole in the question, pythagorean theorem AB^2 + AC^2 = BC^2. For sample input AB^2 + AC^2 = 4, but how will AB^2 + AC = 4.25 this tends to be AC^2 - AC = -0.25 which in return leads to imaginary values of AC. Please clarify me if I am missing anything? |
||||||||||||||
2017-06-30 23:06:05
Simple AC in one go :) look for input data type and precision. |
||||||||||||||
2017-06-25 10:57:14 Anand Kumar
took time.. but finally got it... |
||||||||||||||
2017-06-08 14:06:41
Use s = AB^2 + AC and pythagoras theorem AB^2 + AC^2 = (2r)^2(traingle in a semi circle is right angled) Then differentiate. Simple maxima |