[백준_Math]1085_직사각형에서 탈출
쉽게 해결할 수 있는 '직사각형에서 탈출' 문제...!
그냥 x와 w를 비교한 값인 width 그리고 y와 h를 비교한 값인 height 만들고, x, y, width, height 중 가장 작은 값을 출력하면 된다!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package algorithms; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Al1085 { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer token = new StringTokenizer(br.readLine()); int x = Integer.parseInt(token.nextToken()); int y = Integer.parseInt(token.nextToken()); int w = Integer.parseInt(token.nextToken()); int h = Integer.parseInt(token.nextToken()); System.out.println(check(x,y,w,h)); } /* 거리check method */ public static int check(int x, int y, int w, int h){ int ans = Integer.MAX_VALUE; int width = w - x; int height = h - y; ans = Math.min(width, height); ans = Math.min(ans, x); ans = Math.min(ans, y); return ans; } } | cs |
조금씩 더 어려운 문제에 도전해봐야겠다.
'Algorithms' 카테고리의 다른 글
[백준_BFS]2178번_미로 탐색 (0) | 2019.01.05 |
---|---|
[백준_Math]1978_소수 찾기(에라토스테네스의 체) (0) | 2018.12.08 |
[백준_Math]1475_방 번호 (0) | 2018.12.01 |
[백준_Queue]1158_조세퍼스 문제 (0) | 2018.11.25 |
[백준_Queue]1966번_프린터 큐 (0) | 2018.11.18 |