https://www.acmicpc.net/problem/1297
코드 (C)
#include <stdio.h>
#include <math.h>
int main()
{
int d, h, w;
scanf("%d %d %d", &d, &h, &w);
double rate = d/sqrt(h * h + w * w);
printf("%d %d", (int)(h * rate), (int)(w * rate));
return 0;
}
코드 (C++)
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int d, h, w;
cin >> d >> h >> w;
double rate = d / sqrt(h * h + w * w);
cout << (int) (h * rate) << " " << (int)(w * rate);
return 0;
}
코드설명
아래 그림을 바탕으로 코드를 작성했다.
느낀 점
그림을 직접 그려보고 식을 세워서 풀었다.
'PS (C, C++)' 카테고리의 다른 글
[백준/C & C++] 5724 파인만 (0) | 2022.09.04 |
---|---|
[백준/C & C++] 2920 음계 (0) | 2022.09.04 |
[백준/C & C++] 7568 덩치 (0) | 2022.09.03 |
[백준/C & C++ ] 9020 골드바흐의 추측 (0) | 2022.08.29 |
[백준/C & C++] 11047 동전 0 (0) | 2022.08.29 |