๐Ÿ’  BOJ/Class 2

[BOJ][C++] ๋ฐฑ์ค€ 1085๋ฒˆ: ์ง์‚ฌ๊ฐํ˜•์—์„œ ํƒˆ์ถœ

์„ ๋‹ฌ 2023. 4. 6. 01:14
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/1085

 

1085๋ฒˆ: ์ง์‚ฌ๊ฐํ˜•์—์„œ ํƒˆ์ถœ

ํ•œ์ˆ˜๋Š” ์ง€๊ธˆ (x, y)์— ์žˆ๋‹ค. ์ง์‚ฌ๊ฐํ˜•์€ ๊ฐ ๋ณ€์ด ์ขŒํ‘œ์ถ•์— ํ‰ํ–‰ํ•˜๊ณ , ์™ผ์ชฝ ์•„๋ž˜ ๊ผญ์ง“์ ์€ (0, 0), ์˜ค๋ฅธ์ชฝ ์œ„ ๊ผญ์ง“์ ์€ (w, h)์— ์žˆ๋‹ค. ์ง์‚ฌ๊ฐํ˜•์˜ ๊ฒฝ๊ณ„์„ ๊นŒ์ง€ ๊ฐ€๋Š” ๊ฑฐ๋ฆฌ์˜ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ

www.acmicpc.net

 

๋ฌธ์ œ

ํ•œ์ˆ˜๋Š” ์ง€๊ธˆ (x, y)์— ์žˆ๋‹ค. ์ง์‚ฌ๊ฐํ˜•์€ ๊ฐ ๋ณ€์ด ์ขŒํ‘œ์ถ•์— ํ‰ํ–‰ํ•˜๊ณ , ์™ผ์ชฝ ์•„๋ž˜ ๊ผญ์ง“์ ์€ (0, 0), ์˜ค๋ฅธ์ชฝ ์œ„ ๊ผญ์ง“์ ์€ (w, h)์— ์žˆ๋‹ค. ์ง์‚ฌ๊ฐํ˜•์˜ ๊ฒฝ๊ณ„์„ ๊นŒ์ง€ ๊ฐ€๋Š” ๊ฑฐ๋ฆฌ์˜ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— x, y, w, h๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ๋ฌธ์ œ์˜ ์ •๋‹ต์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

// https://whkakrkr.tistory.com

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int x, y, w, h;
    cin >> x >> y >> w >> h;
    
    cout << min({x, y, w-x, h-y});
}
๋ฐ˜์‘ํ˜•