Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 프로그래머스 도둑질 java
- mysql
- 자바
- 프로그래머스 숫자의 표현 java
- 코딩테스트
- 네트워크
- time complexity
- 백준 16927
- java 내림
- 백준 18290
- Math.floor()
- 백준 15661
- 백준 17425
- 프로그래머스 연속된 수의 합 java
- java 올림
- Codility
- Arrays
- 0으로 채우기
- sort
- 백준 4375
- Math.ceil()
- 백준 14391
- 프로그래머스 옹알이 java
- java 반올림
- 알고리즘
- 백준 16935
- java
- 프로그래머스 네트워크 java
- Algorithm
- 백준 11723
Archives
- Today
- Total
취미처럼
[백준] 1107번 리모컨 본문
https://www.acmicpc.net/problem/1107
1107번: 리모컨
첫째 줄에 수빈이가 이동하려고 하는 채널 N (0 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 고장난 버튼의 개수 M (0 ≤ M ≤ 10)이 주어진다. 고장난 버튼이 있는 경우에는 셋째 줄에는 고장난 버튼
www.acmicpc.net
0 부터 최대값까지 모든 번호를 다 누르고, +, - 이동 후에 최소값 선택
최대 채널은 500000이나 위에서부터 이동하는 경우도 있으므로 999999 가 최대값
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
ArrayList<Integer> brokenNumbers = new ArrayList<>();
int min = Integer.MAX_VALUE;
Scanner sc = new Scanner(System.in);
int target = sc.nextInt();
int brokenCount = sc.nextInt();
for(int i = 0; i < brokenCount; i++) {
int num = sc.nextInt();
brokenNumbers.add(num);
}
// 100번에서 +, -로만 채널 변경
min = Math.min(min, Math.abs(target - 100));
for(int i = 0; i < 1000000; i++) {
String str = String.valueOf(i);
int len = str.length();
boolean isBreak = false;
for(int j = 0; j < len; j++) {
// 고장난 버튼일 때
if(brokenNumbers.contains(str.charAt(j) - '0')) {
isBreak = true;
break;
}
}
if(!isBreak){ // i가 고장난 버튼이 아니라면
// i를 누른후(len) + 목표채널까지 이동하는 횟수
int count = Math.abs(target - i) + len;
min = Math.min(min, count);
}
}
System.out.println(min);
}
}'Algorithm > 백준' 카테고리의 다른 글
| [백준] 6064번 카잉 달력 (0) | 2021.03.02 |
|---|---|
| [백준] 14500번 테트로미노 (0) | 2021.03.02 |
| [백준] 1476번 날짜 계산 (0) | 2021.02.25 |
| [백준] 3085번 사탕 게임 (0) | 2021.02.25 |
| [백준] 2309번 일곱 난쟁이 (0) | 2021.02.25 |
Comments