본문 바로가기

Java

(20)
[백준] 11047번 동전 0 - 그리디 알고리즘 / 탐욕 알고리즘 문제 My Code import java.io.*; public class Main { static int resultNum; public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); // N, K 입력 받기 String str = bf.readLine(); int n = Integer.parseInt(str.split(" ")[0]); int k = Integer.parseInt(str.split(" ")[1]); int count = 0; // 동전 개수 변수 선언 및 초기화 int[] arr = new int[n]; //..
[백준] 1920번 수 찾기 - 이진 탐색 알고리즘/ 함수 이용(재귀X) 문제 My Code import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static int[] A; static int resultNum; public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bf.readLine()); A = new int[n]; StringTokenizer st = new StringTokenizer(bf.readLine()); for (..
[백준] 2178번 미로 탐색 - BFS / 너비 탐색 알고리즘 / 클래스 문제 My Code import java.io.*; import java.util.LinkedList; import java.util.Queue; class ArrGraph{ private int[][] arrGrapgh; //인접 행렬 선언 boolean[][] visit; // 방문 배열 선언 private int n, m; //행과 열 선언 //상하좌우 탐색 배열 선언 및 초기화 private int[] dx = {0, 1, 0, -1}; private int[] dy = {1, 0, -1, 0}; //생성자 public ArrGraph(int n, int m) { this.arrGrapgh = new int[n][m]; this.visit = new boolean[n][m]; this.n = n;..
[Java] BFS 구현하기 - 재귀 함수&Queue이용 / 인접 리스트 ex) Code import java.io.*; import java.util.LinkedList; import java.util.Queue; public class Main { static LinkedList[] adj; static boolean[] visit; static Queue queue; public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //정점과 간선 선언 및 저장 String str = bf.readLine(); int n = Integer.parseInt(str.split(" ")[0]); int m ..
[백준] 11724번 연결 요소의 개수 - DFS방식 / 재귀 함수 이용/ 무방향 그래프 문제 My Code import java.io.*; import java.util.LinkedList; import java.util.Stack; public class Main { static LinkedList[] linkedList; static Stack stack; static int[] result; static int index = 0; static boolean[] tf; public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int[] input = new int[2]; stack = new Stack(); ..
[Java] DFS 구현하기 - 재귀 함수 이용 / 인접 리스트 / 배열 ex) Code import java.io.*; import java.util.LinkedList; public class Main { static LinkedList[] linkedList; static boolean[] visit; public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //정점과 간선 입력&저장 String str = bf.readLine(); int n = Integer.parseInt(str.split(" ")[0]); int m = Integer.parseInt(str.split(" ")[1]); ..
[백준] 1517번 버블 소트 - 병합 정렬 / 버블 정렬 문제 My Code import java.io.*; import java.util.StringTokenizer; public class Main { static int[] testArray; static int count; public static void main(String[] args) throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(bf.readLine()); int[] array = new int[N]; testArray = new int[N]; count = 0; StringTokenizer st = new StringTokeniz..
[백준] 11004번 K번째 수 - 퀵정렬 / 오름차순 정렬 문제 My Code import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int N; int findindex; int [] input = new int[2]; int start, end, pivot; StringTokenizer st = new StringTokenizer(bf.readLine()); for (int i = 0; i pivot && end < pivot) { numArray[i..