본문 바로가기

짱구 굴리기 (Q) - 52

[백준 4963] 섬의 개수 출처 : https://www.acmicpc.net/problem/4963 BFS문제입니다 전체 소스 입니다 public class Q4963 { public static int[] nX = {-1, 0, 1, -1, 1, -1, 0, 1}; public static int[] nY = {-1, -1, -1, 0, 0, 1, 1, 1}; public static void main(String[] args) throws IOException{ Q4963 to = new Q4963(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int w; int h; int[][] arr; whil.. 2019. 1. 16.
[백준1260] DFS와 BFS DFS와 BFS를 출력하는 가장 기초적인 문제입니당 메인부분 public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int dot = Integer.parseInt(st.nextToken()); int edge = Integer.parseInt(st.nextToken()); int start = Integer.parseInt(st.nextToken()); Vertex[] v = new Vertex[dot+1]; for(int.. 2019. 1. 11.
[프로그래머스] 쇠막대기 (스택/큐) 출처 : https://programmers.co.kr/learn/courses/30/lessons/42585 스택을 사용하여 해결함~ 첨엔 잘 몰라서 손으로 그려가면서 어떻게 돌아가는지 찾아보았음 일반적인 괄호문제와 비슷하게 돌아가면서 - [ ( : push, ) : pop 을 시켜줌 ] 1. pop을 할 시 이 부분이 레이저인지, 아닌지를 판별해줘야 함 . 이 부분은 반복문을 돌면서 이전에 들어온 문자를 저장하여 사용. 조건에 여는 괄호와 닫는 괄호는 항상 쌍을 이룬다 나왔기 때문에 별 다른 상황 생각을 안함 2. 레이저일 경우 : pop을 하고 현재 스택의 사이즈만큼 더해줌 3. 레이저가 아닐경우 : 이 부분은 막대기가 없어졌단 소리로 pop을 해주고 1을 더해줌 (막대기 꼬랑지부분을 처리해야 하기.. 2019. 1. 9.
[백준 2750] 수 정렬하기 public class Q2750 { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int[] arr = new int[n]; int size = arr.length; for(int i=0; i 2018. 12. 13.