Algorithm/BOJ
[BOJ] 1297번 TV 크기 C# 사용 풀이
Bueong_E
2023. 2. 8. 00:35
반응형
SMALL
문제
문제풀이
using System;
using System.IO;
namespace BOJ1297
{
internal class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
int[] DHW = Array.ConvertAll(sr.ReadLine().Split(), int.Parse);
double D = DHW[0]; // 대각선 길이
double H = DHW[1]; // 높이 비율
double W = DHW[2]; // 너비 비율
//높이와 너비 각각의 실제 길이를 구하는 피타고라스 공식
// D^2 = (H*x)^2 + (W*x)^2
//여기서 x 는 (D)^2 / (H^2 + W^2)의 제곱근
double x = Math.Sqrt(D * D / (H * H + W * W));
// 소수점 버리고 변수에 담기
double result1 = Math.Truncate(H * x);
double result2 = Math.Truncate(W * x);
sw.WriteLine("{0} {1}", result1, result2);
sr.Close();
sw.Close();
}
}
}
결과창
피타고라스의 정리를 다시 한번 더 정리해봐야겠다.
아직 수학공식이 필요한 알고리즘은 많이 약하다 ㅠㅠ
PS. 실수 타입의 변수를 활용해야하는 예제들도 좀 더 풀어봐야겠다.
반응형
LIST