MAXLN - THE MAX LINES Editorial SPOJ - Unleash-Coding-Skills

## MAXLN - THE MAX LINES

The link for the problem MAXLN - THE MAX LINES :

http://www.spoj.com/problems/MAXLN/

Explanation: Angle in a semi-circle is a right angle always, hence, the triangle formed  is a Right angled triangle (Thales’ theorem).
So, now we have :
AB2+AC2=BC2
AB2+AC2=(2r)2
AB2=4r2AC2
In the question we have this equation:
s=AB2+AC
s=4r2AC2+AC
s=AC2+AC+ 4r2
Now we have a quadratic equation, and we have to find its maximum. Maximum value occurs when
AC=-b/2a
So now using values of a and b from equation we get :
AC=-b/2a
AC=-1/-2
AC=1/2
Putting the value of AC in equation we get :
s=(1/2)2+1/2+4r2
s=(1/4)+1/2+4r2
s1/4+4r2
s=0.25+4r2
Hence the equation we are going to use is :
s=0.25+4r2
The solution for the problem MAXLN - THE MAX LINES :

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for (int i = 0; i < t; i++) {
double n = s.nextDouble();
double f = 0.25 + 4 * n * n;
System.out.printf("Case %d: %.2f\n", i + 1, f);
}
}
}