알고리즘

알고리즘

<백준> 1260번 자바 알고리즘 [BFS, DFS]

public class Main { static int n, m, v; // 정점, 간선, 시작점 static ArrayList[] al; static boolean visited[]; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stz = new StringTokenizer(br.readLine()); n = Integer.parseInt(stz.nextToken()); m = Integer.parseInt(stz.nextToken()); v = Integer.parseInt(stz.n..

알고리즘

<백준> 1707번 자바 알고리즘 [BFS][이분 그래프]

import java.util.*; import java.io.*; public class Main { static int v, e; // 정점, 간선 static ArrayList[] al; // 연결 정보 저장 static int visit[]; // 초기화 0, 이후 1 or 2 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stz = new StringTokenizer(br.readLine()); int t = Integer.parseInt(stz.nextToken()); for(i..

알고리즘

<백준> 7562번 자바 알고리즘[BFS]

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.*; public class Main { static class Loc { int x; int y; public Loc(int x, int y){ this.x = x; this.y = y; } } static int start_x, start_y, end_x, end_y; static int[] dx = {-2, -1, 1, 2, 2, 1, -1, -2}; static int[] dy = {1, 2, 2, 1, -1,..

알고리즘

<백준> 2206번 자바 알고리즘[BFS]

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; public class Main { static class Loc{ int i; // 가로 int j; // 세로 int dis; boolean des; public Loc(int i, int j, int dis, boolean des){ this.i = i; this.j = j; this.dis = dis; this.des = des; } } public static void main(String[] args) throws IOException ..

알고리즘

<백준> 1697번 자바 알고리즘[BFS]

import java.util.*; class Main { static int[] check = new int[100001]; static int n, k; public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); k = in.nextInt(); if (n == k) { System.out.println(0); } else { System.out.println(bfs(n)); } } private static int bfs(int f){ Queue queue = new LinkedList(); queue.add(f); int idx = f; int a = 0; check[idx] = 1; w..

알고리즘

<백준> 7569번 자바 알고리즘 [BFS]

import java.io.*; import java.util.*; class PointXYZ { int height; int row; int colume; public PointXYZ(int height, int row, int colume){ this.height = height; this.row = row; this.colume = colume; } } public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static int rowArr[] = {-1, 0, 1, 0, 0, 0}; static int colArr[] = {0, 1, 0, -1, 0, 0}; static in..

알고리즘

<백준> BFS 자바 알고리즘

import java.util.*; public class Main { static int n, m, k; // n = 정점, m = 간선, k = 시작 노드 public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); boolean[] visited = new boolean[n + 1]; LinkedList[] adjList = new LinkedList[n + 1]; for(int i = 1; i

알고리즘

<백준> 6064번 자바 알고리즘

import java.util.*; public class Main { static int N, M, x, y, T; public static void main(String[] args) { Scanner in = new Scanner(System.in); T = in.nextInt(); for(int i=0; i < T; i++){ M = in.nextInt(); N = in.nextInt(); x = in.nextInt(); y = in.nextInt(); if(y == N){ // N으로 나눴을 때 y 가 0일 경우를 대비하여 먼저 y를 0으로 바꾼다 y = 0; } int MAXxy = M * N; // 가장 최대 int idx = 0; int res = -1; while(true){ if((M ..

알고리즘

<백준> 14889번 자바 알고리즘

import java.util.*; public class Main { static int N; static int[][] arr; static boolean[] visit; static int MIN = Integer.MAX_VALUE; public static void main(String[] args) { Scanner in = new Scanner(System.in); N = in.nextInt(); arr = new int[N][N]; visit = new boolean[N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { arr[i][j] = in.nextInt(); } } Bp(0, 0); System.out.println(MIN)..

알고리즘

<백준> 14888번 자바 알고리즘

import java.util.*; public class Main { static int MAX = Integer.MIN_VALUE; static int MIN = Integer.MAX_VALUE; static int[] numbers, operator; static int N; public static void main(String[] args) { Scanner input = new Scanner(System.in); N = input.nextInt(); numbers = new int[N]; operator = new int[4]; for(int i=0; i < N; i++){ numbers[i] = input.nextInt(); } for (int i = 0; i < 4; i++) { opera..

changha.
'알고리즘' 카테고리의 글 목록 (5 Page)