답안 :
package answer;
class Solution {
/*
* 1. 전체 타일의 갯수를 합산.
* 2. 높이를 최소 3으로 구성 (노란색이 1개이상있을시 3이상)
* 3. 전체타일 / 높이 = 길이
* 4. (width - 2) * (hight - 2) = 상하, 좌우 테두리를 제외하고 노란색의 갯수가 같다면 카펫의 크기.
* */
public int[] solution(int brown, int yellow) {
int[] answer = new int[2];
int allTile = brown + yellow;
int width = 0;
int hight = 3;
for (int i = 3; i < allTile; i++) {
hight = i;
if (allTile % i == 0) {
width = allTile / i;
if ((width - 2) * (hight - 2) == yellow) {
answer[0] = width;
answer[1] = hight;
break;
}
}
}
return answer;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s = new Solution();
int brown = 8;
int yellow = 1;
System.out.println(s.solution(brown, yellow));
}
}
완전탐색(Brute Force) : 모든 경우의 수를 다 체크해서 정답을 찾는 방법이다. 즉, 무식하게 가능한 거 다 해보겠다는 방법을 의미한다.
- managerId가 5이상인 id를 가진 직원의 이름을 출력
SELECT e.name
FROM Employee AS e
INNER JOIN Employee AS m ON e.id=m.managerId
GROUP BY m.managerId
HAVING COUNT(m.managerId) >= 5