C++/백준 코딩테스트 풀이 C++
C++ 1085 직사각형에서 탈출 / 제곱 / 제곱근 / 최소값
jjiing
2022. 6. 27. 11:36
dis배열에 직사각형의 네 변에 내린 수선의 길이(의 제곱)를 구해주고, 최소값을 찾아 루트를 씌워준다.
사용한 함수
1. 제곱 & 제곱근
#include <math.h>
제곱 : pow(밑, 지수)
제곱근 : sqrt(숫자)
2. 최대값, 최소값
#include <algorithm>
<배열>
*max_element(배열, 배열+배열크기)
*min_element(배열, 배열+배열크기)
<벡터>
*max_element(벡터.begin(), 벡터.end())
*min_element(벡터.begin(), 벡터.end())
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
float dis[4];
int x, y, w, h;
cin >> x >> y >> w >> h;
dis[0] = pow(y,2);
dis[1] = pow(x, 2);
dis[2] = pow((w-x), 2);
dis[3] = pow((h-y), 2);
int maxDis = *min_element(dis, dis+4);
cout << sqrt(maxDis)<<endl;
}