- toc {:toc}
λ¬Έμ
νμλ μ§κΈ (x, y) μ μλ€. μ§μ¬κ°νμ κ° λ³μ΄ μ’νμΆμ νννκ³ ,Β μΌμͺ½ μλ κΌμ§μ μ (0, 0), μ€λ₯Έμͺ½ μ κΌμ§μ μ (w, h) μ μλ€. μ§μ¬κ°νμ κ²½κ³μ κΉμ§ κ°λ 거리μ μ΅μκ°μ ꡬνλ νλ‘κ·Έλ¨μ μμ±νμμ€.
μ λ ₯
첫째 μ€μ x, y, w, h κ° μ£Όμ΄μ§λ€.
μΆλ ₯
첫째 μ€μ λ¬Έμ μ μ λ΅μ μΆλ ₯νλ€.
μ ν
- 1 β€ w, h β€ 1,000
- 1 β€ x β€ w-1
- 1 β€ y β€ h-1
- x, y, w, h λ μ μ
μΆμ²:https://www.acmicpc.net/problem/1085
νμ΄
- μΌνμ°μ°μλ₯Ό μ¬μ©ν΄λ΄€λ€.
- 거리 β μμ§μΌλ‘ λ΄λ €μΌ ν¨. β μΆκ³Ό ννν λ©΄μΌλ‘ μμ§μΌλ‘ λ΄λ €μΌ νκΈ° λλ¬Έμ κ²°κ΅ νκ°μ κ²½μ° x κ° 0, w λ μ€ μ΄λ€ κ²κ³Ό κ°κΉμ΄μ§, λμ΄μ κ°μ κ²½μ° y κ° 0, h λ μ€ μ΄λ€ κ²κ³Ό κ°κΉμ΄μ§λ₯Ό νμΈνλ©΄ λλ€.
#include <iostream>
using namespace std;
int minDistance(int x, int y, int w, int h);
int main()
{
int x, y, w, h;
cin >> x >> y >> w >> h;
cout << minDistance(x, y, w, h) << endl;
return 0;
}
int minDistance(int x, int y, int w, int h)
{
int mW, mH;
(w/2<x)? mW=w-x:mW=x;
(h/2<y)? mH=h-y:mH=y;
return (mW<mH)? mW : mH;
}