코드와이
[BAEKJOON] 14226. 이모티콘 본문
문제링크
https://www.acmicpc.net/problem/14226
14226번: 이모티콘
영선이는 매우 기쁘기 때문에, 효빈이에게 스마일 이모티콘을 S개 보내려고 한다. 영선이는 이미 화면에 이모티콘 1개를 입력했다. 이제, 다음과 같은 3가지 연산만 사용해서 이모티콘을 S개 만
www.acmicpc.net
package acmicpc.Gold5;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class 이모티콘 {
static class Point{
int x, cnt, clip;
public Point(int x, int cnt, int clip) {
super();
this.x = x;
this.cnt = cnt;
this.clip = clip;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
Queue<Point> queue = new LinkedList<>();
boolean[] visited = new boolean[2000];
queue.add(new Point(1, 1, 1));
int ans = 0;
if(s == 1) {
ans = 0;
} else {
while(!queue.isEmpty()) {
Point q = queue.poll();
if(q.x == s) {
ans = q.cnt;
break;
}
// 클립보드에 복사
if(q.x != q.clip) queue.add(new Point(q.x, q.cnt + 1, q.x));
// 클립보드에 있는 이모티콘 붙여넣기
if(q.x + q.clip <= 1500) {
queue.add(new Point(q.x + q.clip, q.cnt + 1, q.clip));
visited[q.x + q.clip] = true;
}
// 하나 삭제
if(q.x - 1 > 1 && !visited[q.x - 1]) {
queue.add(new Point(q.x - 1, q.cnt + 1, q.clip));
visited[q.x - 1] = true;
}
}
}
System.out.println(ans);
}
}
'acmicpc' 카테고리의 다른 글
[BAEKJOON] 2668. 숫자고르기 (0) | 2021.07.14 |
---|---|
[BAEKJOON] 1033. 감소하는 수 (0) | 2021.07.14 |
[BAEKJOON] 2470. 두 용액 (0) | 2021.07.09 |
[BAEKJOON] 2631. 줄 세우기 (0) | 2021.07.07 |
[BAEKJOON] 11559. Puyo Puyo (0) | 2021.07.06 |