Nos dan un semicírculo de radio R. Podemos tomar cualquier punto de la circunferencia sea P. Ahora, desde ese punto P trazamos dos rectas a los dos lados del diámetro. Sean las rectas PQ y PS .
La tarea es encontrar el valor máximo de la expresión PS 2 + PQ para un R dado.
Ejemplos:
Input : R = 1 Output : 4.25 (4*1^2 + 0.25) = 4.25 Input : R = 2 Output : 16.25 (4 * 2^2 + 0.25)= 16.25
Sea F = PS^2 + PQ. Sabemos QS = 2R (Diámetro del semicírculo)
-> También sabemos que el triángulo PQS siempre será un triángulo rectángulo independientemente de la posición del punto P en la circunferencia del círculo
1.)QS^2 = PQ^2 + PS^2 (Pythagorean Theorem) 2.) Adding and Subtracting PQ on the RHS QS^2 = PQ^2 + PS^2 + PQ - PQ 3.) Since QS = 2R 4*R^2 + PQ - PQ^2 = PS^2 + PQ => 4*R^2 + PQ - PQ^2 = F 4.) Using the concept of maxima and minima differentiating F with respect to PQ and equating it to 0 to get the point of maxima for F i.e. 1 - 2 * PQ = 0 => PQ = 0.5 5.) Now F will be maximum at F = 4*R^2 + 0.25
C++
// C++ program to find // the maximum value of F #include <bits/stdc++.h> using namespace std; // Function to find the // maximum value of F double maximumValueOfF (int R) { // using the formula derived for // getting the maximum value of F return 4 * R * R + 0.25; } // Drivers code int main() { int R = 3; printf("%.2f", maximumValueOfF(R)); return 0; }
JAVA
// JAVA program to find // the maximum value of F import java.io.*; class GFG { // Function to find the // maximum value of F static double maximumValueOfF (int R) { // using the formula derived for // getting the maximum value of F return 4 * R * R + 0.25; } // Driver code public static void main (String[] args) { int R = 3; System.out.println(maximumValueOfF(R)); } } // This code is contributed // by anuj_67.
Python3
# python program to find # the maximum value of F # Function to find the # maximum value of F def maximumValueOfF (R): # using the formula derived for # getting the maximum value of F return 4 * R * R + 0.25 # Drivers code R = 3 print(maximumValueOfF(R)) # This code is contributed by Sam007.
C#
// C# program to find the // maximum value of F using System; class GFG { // Function to find the // maximum value of F static double maximumValueOfF (int R) { // using the formula derived for // getting the maximum value of F return 4 * R * R + 0.25; } // Driver code public static void Main () { int R = 3; Console.WriteLine(maximumValueOfF(R)); } } // This code is contributed by Sam007.
PHP
<?php // PHP program to find the // maximum value of F // Function to find the // maximum value of F function maximumValueOfF ($R) { // using the formula derived // for getting the maximum // value of F return 4 * $R * $R + 0.25; } // Drivers code $R = 3; echo maximumValueOfF($R); // This code is contributed // by anuj_67. ?>
Javascript
<script> // javascript program to find the // maximum value of F // Function to find the // maximum value of F function maximumValueOfF(R) { // using the formula derived for // getting the maximum value of F return 4 * R * R + 0.25; } // Driver code var R = 3; document.write(maximumValueOfF(R)); // This code is contributed by bunnyram19. </script>
Producción :
36.25
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por Shashank_Pathak y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA