티스토리 뷰
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | import java.util.*; public class Level2_카펫 { public static int[] solution(int brown, int yellow) { // yellow 의 약수 쌍을 구한다. // 약수 쌍을 돌며 가능한 경우 모두 수식에 맞춰 brown 값을 맞춰본다. // w >= h // yellow 블럭의 w, h 를 구하는거니 return 할때는 w+2, h+2 해준다. List<Integer> divisor = getDivisor(yellow); return findBrownCount(brown, divisor); } public static List<Integer> getDivisor(int yellow) { List<Integer> list = new ArrayList(); for (int i = 1; i <= Math.sqrt(yellow); i++) { if (yellow % i == 0) { list.add(i); list.add(yellow/i); } } Collections.sort(list); return list; } public static int[] findBrownCount(int brown, List<Integer> divisor) { int x = 0; int y = divisor.size() - 1; while (true) { int w = divisor.get(x); int h = divisor.get(y); x++; y--; if (h > w) { continue; }; int totalBrown = ((w + 2) * 2) + (h * 2); if (totalBrown == brown) { return new int[] {w+2, h+2}; } } } public static void main(String[] args) { int brown = 24; int yellow = 24; int[] solution = solution(brown, yellow); System.out.println(solution[0] + ", " + solution[1]); } } | cs |
'PS > programmers' 카테고리의 다른 글
MySQL 2레벨 다 풀었다. (0) | 2021.08.06 |
---|---|
MySQL 1레벨 다 풀었다. (0) | 2021.08.06 |
Level2) H-Index (0) | 2021.05.04 |
Level2) 위장 (0) | 2021.05.03 |
Level1) 내적 (0) | 2021.05.02 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- JS 딥다이브
- JPA 연관관계 매핑
- 패스트캠퍼스 컴퓨터공학 완주반
- 이펙티브자바
- 모던자바스크립트
- 백기선 스터디
- ㅇㄷㅇㅈ
- 프로그래머스 SQL
- 이펙티브자바 아이템60
- http
- js promise
- HTTP 완벽 가이드
- 킹수빈닷컴
- dreamcoding
- 드림코딩
- 이펙티브자바 스터디
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- js array
- 백준
- 김영한 http
- java
- REST API
- 프로그래머스
- HTTP 완벽가이드
- 이펙티브자바 아이템59
- 김영한 JPA
- GCP
- Spring Security
- BOJ
- js api
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함