![[백준 / BOJ] 1085번 직사각형에서 탈출 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbevLKW%2FbtrJp0ip8uW%2Fbed8UNRxpqRWjAobm1NNgK%2Fimg.png)
[백준 / BOJ] 1085번 직사각형에서 탈출 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 6. 2. 20:19
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/1085
1085번: 직사각형에서 탈출
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램
www.acmicpc.net
문제

문제 풀이
그림을 그려보면 쉽게 풀린다.

C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
void init() { | |
std::ios_base::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
std::cout.tie(nullptr); | |
} | |
int main() { | |
init(); | |
int x, y, w, h; | |
std::cin >> x >> y >> w >> h; | |
int res1 = std::min(x, y); | |
int res2 = std::min(w - x, h - y); | |
std::cout << std::min(res1, res2) << "\n"; | |
return 0; | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x, y, w, h = map(int, input().split()) | |
res1 = min(x, y); | |
res2 = min(w - x, h - y); | |
print(min(res1, res2)) |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 2477번 참외밭 (C++, Python) (0) | 2022.06.03 |
---|---|
[백준 / BOJ] 3009번 네 번째 점 (C++, Python) (0) | 2022.06.02 |
[백준 / BOJ] 11478번 서로 다른 부분 문자열의 개수 (C++, Python) (0) | 2022.06.01 |
[백준 / BOJ] 1269번 대칭 차집합 (C++, Python) (0) | 2022.06.01 |
[백준 / BOJ] 1764번 듣보잡 (C++, Python) (0) | 2022.06.01 |
@Reo :: 코드 아카이브
자기계발 블로그