코딩테스트 문제 풀이/[백준]이분 탐색(5)
-
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 -
C# 1654번 랜선 자르기
코드 : using System; namespace _3 { class Program { static void Main(string[] args) { int[] K_N = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); //K long K = K_N[0]; //N long N = K_N[1]; //랜선의 전체길이 long lengthSum = 0; //랜선배열 long[] lengthArr = new long[K]; //랜선 전처리 for (int i = 0; i < K; i++) { long length = long.Parse(Console.ReadLine()); lengthArr[i] = length; lengthSum += length; }..
2022.02.24 -
C# 10816번 숫자 카드2
코드 : using System; using System.Linq; using System.Text; namespace _2 { class Program { static int N = Convert.ToInt32(Console.ReadLine()); static int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); static int M = Convert.ToInt32(Console.ReadLine()); static int[] M_Array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); static StringBuilder sb = new StringBuilder();..
2022.02.24 -
C# 1920번 수 찾기
시간초과 코드 : using System; using System.Linq; using System.Text; namespace _1 { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int M = Convert.ToInt32(Console.ReadLine()); int[] A2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); StringBuilder sb = new StringBuilder(); ..
2022.02.24