[백준] 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..
[백준] Gold V. 집합의 표현
·
Algorithm/백준
https://www.acmicpc.net/problem/1717 알고리즘 유형그래프유니온 파인드 풀이import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class boj1717 { static int n, m; static int [] parent; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ..
[그래프] 위상정렬
·
Algorithm/백준
위상정렬 (Topological sort) 방향 그래프에서 간선으로 주어진 정점 간 선후 관계를 위배하지 않도록 나열하는 정렬 그래프 안에서 사이클이 존재하는 경우엔, 위상정렬을 적용할 수 없다. 근데, 사이클이 존재한다는 뜻이 무슨 뜻일까?  위와 같은 그래프가 존재한다고 가정할 떄, A->B->C->A... 이런식으로 다시 돌아올 때를 사이클이 존재한다고 한다. 즉, 한 노드에서 다른 노드들을 거쳐 처음 노드로 돌아오는 경우, 사이클이 존재한다고 얘기할 수 있다.  위와 같은 그래프가 주어졌을 때, 어떤 노드를 먼저 우선적으로 방문해야 할까? 우선적으로, indegree 배열을 만들어서 각 노드의 indegree 개수를 확인해보자. ABCDEFG0301210 indegree가 0인 정점을 살펴보면 A..