본문 바로가기

알고리즘

(70)
백준 14502 - 연구소(새 풀이) 백트래킹 + BFS import java.util.*; public class boj14502_연구소 { static int[] dy = {-1, 1,0, 0}; static int[] dx = {0, 0, -1, 1}; static int N, M; static int[][] map, temp; static boolean[] visited; static LinkedList pick = new LinkedList(); static int result = 0; static int safeCount = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); // 세로 M = sc.next..
SWEA - 벌꿀채취 벌꿀 채취 삼성모의 기출 벌꿀의 합을 DFS를 활용한 모든 경우의 수를 통해 더하는게 주요 포인트 import java.sql.Array; import java.sql.CallableStatement; import java.util.*; import java.io.FileInputStream; class Solution { static int N, M, C; static int[][] map; static int resultMax = -987654321; static List list; static boolean[] visited; static class Pos{ int y; int x; int sum; Pos(int y, int x, int sum){ this.y = y; this.x = x; this..
백준 - 14503 로봇청소기(삼성 SW 기출) https://www.acmicpc.net/problem/14503 14503번: 로봇 청소기 로봇 청소기가 주어졌을 때, 청소하는 영역의 개수를 구하는 프로그램을 작성하시오. 로봇 청소기가 있는 장소는 N×M 크기의 직사각형으로 나타낼 수 있으며, 1×1크기의 정사각형 칸으로 나누어져 있다. 각각의 칸은 벽 또는 빈 칸이다. 청소기는 바라보는 방향이 있으며, 이 방향은 동, 서, 남, 북중 하나이다. 지도의 각 칸은 (r, c)로 나타낼 수 있고, r은 북쪽으로부터 떨어진 칸의 개수, c는 서쪽으로 부터 떨어진 칸의 개수이다. 로봇 청소기는 다음 www.acmicpc.net 시뮬레이션 문제로 풀었습니다. 문제에서 설명하는대로 구현하면 되기 때문에 문제를 잘 읽으려고 많이 노력했습니다. 그리고 기능단위별..
백준 - 14502 연구소 DFS의 개념이 필요한 문제였습니다. 다음에 다시 한번 보도록 해야겠습니다. package com.company; import java.util.Scanner; public class boj14502version2 { static int N, M,totalCNT; static int[][] map, visited; static int[] dx = {0, -1, 0, 1}; static int[] dy = {-1, 0, 1, 0}; public static void main(String[] args){ Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); map = new int[N][M]; visited = new int[N][..
백준 14889 - 스마트와 링크 백트래킹을 활용한 문제입니다. 조합의 개념이 들어가서 상당히 애먹었기때문에 다른 분의 풀이를 참조했습니다. package com.company; import java.util.LinkedHashMap; import java.util.Scanner; public class boj14889 { static int N; static int[][] map; static boolean visited[]; static int min=99999999; public static void main(String[] args){ Scanner sc = new Scanner(System.in); N = sc.nextInt(); map = new int[N+1][N+1]; visited = new boolean[N+1]; fo..
백준 17144번 - 미세먼지 안녕!(런타임 에러) 시뮬레이션 문제입니다. 런타임 에러가 나와서 아직 방법을 못찾았습니다. 혹시 스캐너로 입력을 받는 것이 문제일까 싶어서 버퍼리더로 받았는데도 동일한 문제가 나오는 걸 보니 공기청정기에서 배열 접근하는 방법에서 문제가 있는게 아닐까 의심되네요 ㅠㅠ 시간 날 때 다시 한번 풀어봐야겠습니다. package com.company; import java.util.Scanner; public class boj17144 { static int N, M, T; static int[][] map, temp, cnt, airMap; static int[] dx = {-1, 1, 0, 0}; static int[] dy = {0, 0, -1, 1}; static int airX1=0; static int airX2=0; s..
프로그래머스 - 구명보트 https://programmers.co.kr/learn/courses/30/lessons/42885 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 구명보트 문제입니다. 처음에는 큐를 활용해서 풀려고하다가 인덱스를 활용하는 것이 더 좋겠다고 생각했습니다. 정렬을 먼저 생각하는 것이 문제의 핵심이였고, 이전에도 프로그래머스 문제를 풀다가 먼저 정렬을 한 후에 풀게되면 쉽게 풀리는 문제가 있었는데 다시 한번 기억해야 되겠습니다. import java.util.Arrays; class Solution { public int solution(int[] peopl..
프로그래머스 - 큰 수 만들기 https://programmers.co.kr/learn/courses/30/lessons/42883 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 그리디는 아직 저한테 버거운것 같습니다.. 풀다가 다른 분들의 풀이를 참고했습니다. class Solution { public String solution(String number, int k) { StringBuilder stringBuilder = new StringBuilder(); int idx = -1; char max; for(int i=0; i< number.length()-k; i++){ max..