전체 글 177

<백준> 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..

알고리즘 2022.01.25

<백준> 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 ..

알고리즘 2022.01.09