11/2 풀이
·
Algorithm/백준
boj 7576 토마토BFS를 여러 지점에서 돌려야 할 때를 어떻게 할것인가?배열에서 익은 토마토에 해당하는 좌표에서 BFS를 돌렸더니 최소 일수를 구할 수 없었다. BFS 특성 상 한 좌표에서 시작해 끝까지 돌기 때문이다. 따라서, 익은 토마토에 해당하는 좌표를 모두 큐에 넣고 한번에 돌려준다면 동시에 BFS를 돌려서 최소 일수를 구할 수 있다. boj 7579 토마토3차원 배열에서의 BFS?상자의 수를 나타내는 H가 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수이렇게 주어질 때,board = new int[h][n][m];형태가 되어야 할 것이다.나머지 로직은 앞의 토마토 문제와 동일하다.
[백준] Silver I. 회전 초밥
·
Algorithm/백준
https://www.acmicpc.net/problem/2531 문제 유형슬라이딩 윈도우투 포인터 코드import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class boj2531 { static int n, d, k, c; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer s..
[백준] Gold V. 강의실 배정
·
Algorithm/백준
https://www.acmicpc.net/problem/11000 문제 유형정렬우선순위 큐 풀이import java.io.*;import java.util.*;public class boj11000 { static int n; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); PriorityQueue pq = new PriorityQueue((a,b) -> { if (a[0] == b..
[프로그래머스] Lv.3 징검다리 건너기
·
Algorithm/프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/64062 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  풀이 유형이분탐색슬라이딩 윈도우 풀이import java.util.*;class Solution { public int solution(int[] stones, int k) { int answer = 0; int st = 1, en = 200000000; while(st   회고 처음엔 매 시간이 지날때마다 돌의 값을 1씩 줄여주고, 이 때 ..
[백준] Silver I. 스타트와 링크
·
Algorithm/백준
https://www.acmicpc.net/problem/14889 문제 유형브루트 포스 백트래킹 풀이public class boj14889 { static int n; static int [][] board; static boolean [] visited; static int res = Integer.MAX_VALUE; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); board = ne..
[백준] Gold IV. 즐거운 단어
·
Algorithm/백준
https://www.acmicpc.net/problem/2922 문제 유형브루트 포스백트래킹 풀이public class boj2922 { static long res = 0; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); dfs(0, 0, 0, input.contains("L"), input, 1); System.out.println(res); } public static void dfs(..
[백준] Silver II. 꽃길
·
Algorithm/백준
https://www.acmicpc.net/problem/14620 문제 유형브루트포스백트래킹 코드 import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class boj14620 { static int n; static int [][] board; static boolean[][] visited; static int[] dx = {1, 0, -1, 0, 0}; static int[] dy = {0, 1, 0, -1, 0}; static int res = Integer.MAX_VALUE; p..
[백준] Gold IV. 케이크 자르기
·
Algorithm/백준
https://www.acmicpc.net/problem/17179  문제생일을 맞이한 주성이가 생일 파티를 준비하려고 한다. 주성이는 일반 케이크 대신 평소 좋아하던 롤 케이크를 준비했다. 롤 케이크에는 장식이 존재해서 특정 위치에서만 자를 수 있다. 주성이는 롤 케이크 조각을 파티에 올 친구의 수 만큼 준비하고 싶어서, 가장 작은 조각의 크기를 미리 알아보기로 했다. 하지만 짓궂은 주성이의 친구들은 생일파티에 몇 명이 참석하는지 직접적으로 알려주지를 않는다. 그래서 몇 개의 수를 목록에 적어, 각 수만큼 조각을 만들었을 때 가장 작은 조각의 길이의 최댓값을 구하려고 한다.예를 들어 70cm의 롤 케이크에 자를 수 있는 지점이 5군데(10cm, 20cm, 35cm, 55cm, 60cm)가 있다고 하자...
[프로그래머스] Lv.3 합승 택시 요금
·
Algorithm/프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/72413 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 사용 알고리즘최단 경로다익스트라플로이드 와샬 풀이 다익스트라import java.util.*;// 4번에서 출발해서 A와 B까지 도달하는 최단경로 노드를 찾는다.// class Solution { static final int INF = Integer.MAX_VALUE / 2; static List> graph = new ArrayList(); public int solution(in..
[백준] Gold IV. 여행 가자
·
Algorithm/백준
https://www.acmicpc.net/problem/1976   사용 알고리즘DFS유니온 파인드 풀이 DFSimport java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;import java.util.StringTokenizer;public class Main { /* 1. 여행 계획 처음부터 BFS를 돌리면서 체크 */ static int n, m; static List> graph = n..