코딩테스트 문제 풀이(88)
-
C# 1012번 유기농 배추
코드 : using System; using System.Collections.Generic; namespace _4 { class Program { static int T,M,N,K; //맵 저장 행렬 static int[,] map = new int[51, 51]; //방문 확인 행렬 static bool[,] visited = new bool[51, 51]; static Queue queue = new Queue(); static int[] dx = { -1, 1, 0, 0 }; static int[] dy = { 0, 0, -1, 1 }; //배추흰지렁이 수 static int count; static void Reset() //초기화 { count = 0; for (int i = 0; i < M..
2022.03.12 -
C# 2667번 단지번호붙이기
코드 : using System; using System.Collections.Generic; namespace _3 { class Program { static int N; //맵 저장 행렬 static int[,] map = new int[26, 26]; //단지내의 집의 수 저장 행렬 static int[] houseCount = new int[1000]; //방문 확인 행렬 static bool[,] visited = new bool[26,26]; static Queue queue = new Queue(); static int[] dx = { -1, 1, 0, 0 }; static int[] dy = { 0, 0, -1, 1 }; //단지수 static int count = 0; //단지내의 집수..
2022.03.04 -
C# 2606번 바이러스
코드 : using System; using System.Collections.Generic; namespace _2 { class Program { static int N; static int M; static int count; static public int[,] map = new int[101, 101]; static public bool[] visited = new bool[101]; static public Queue queue = new Queue(); static void Reset() { for (int i = 1; i
2022.03.04 -
C# 1260번 DFS와 BFS
코드 : using System; using System.Collections.Generic; namespace _1 { class Program { static int[] input; static int N; static int M; static int V; static public int[,] map = new int[1001, 1001]; static public bool[] visited = new bool[1001]; static public Queue queue = new Queue(); static public Stack stack = new Stack(); static void Reset() { for (int i = 1; i
2022.03.04 -
C# 2110번 공유기 설치
코드 : using System; namespace _5 { class Program { static void Main(string[] args) { int[] N_C = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = N_C[0]; int C = N_C[1]; int[] X = new int[N]; for (int i = 0; i < N; i++) { X[i] = Convert.ToInt32(Console.ReadLine()); } Array.Sort(X); long start = 1; long end = X[^1]; //mid의 의미는 공유기간의 거리 //가장 인접한 두 공유기 사이의 거리를 최대로 하라는 말은 //선택한 공유기..
2022.02.24 -
C# 2805번 나무 자르기
코드 : using System; namespace _4 { class Program { static void Main(string[] args) { int[] N_M = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = N_M[0]; int M = N_M[1]; int[] wood = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Array.Sort(wood); long start = 1; long end = wood[^1]; long mid = (start + end) / 2; long sum = 0; while (start = M) { start = mid+1; mid..
2022.02.24