Algorithm


Problem link- https://www.spoj.com/problems/MAXLN/

MAXLN - THE MAX LINES

no tags 

 

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

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <map>
#include <cstdio>

using namespace std;

int main(){
int t=0;
cin>>t;
int count=1;
long long r;
while(t--){
cin>>r;
double ans=((double)r*(double)r)*4+0.25;
printf("Case %d: %.2f\n",count,ans);
count++;
}
return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1
1

Output

x
+
cmd
Case 1: 4.25
Advertisements

Demonstration


SPOJ Solution-THE MAX LINES-Solution in C, C++, Java, Python

Previous
SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python