본문 바로가기

백준/단계별47

백준 15652 C#) N과 M (4) 이전에 풀었던 N과 M (1)과 거의 유사한 문제다. class Program { static StreamWriter sw = new(new BufferedStream(Console.OpenStandardOutput())); static int n, m; static int[] result; static void DFS(int depth, int start) { if (depth == m) { sw.WriteLine(string.Join(' ', result)); return; } for (int i = start; i 2023. 3. 8.
백준 15649 C#) N과 M (1) 백트래킹 및 DFS의 기본을 익힐 수 있는 문제. 시리즈가 굉장히 많으므로 틈틈이 하나씩 풀면 좋다. class Program { static StreamWriter sw = new(new BufferedStream(Console.OpenStandardOutput())); static int n, m; static int[] result; static bool[] visited; static void DFS(int depth) { if (depth == m) { sw.WriteLine(string.Join(' ', result)); return; } for (int i = 1; i 2023. 3. 8.
백준 1002 C#) 터렛 간단한 중~고등학교 수준의 수학 문제. 두 원의 교점 개수를 묻는 문제였다. class Program { static void Main() { StreamWriter sw = new(new BufferedStream(Console.OpenStandardOutput())); int t; int[] xyr; int x1, y1, r1; int x2, y2, r2; double dist; t = int.Parse(Console.ReadLine()); while (t-- > 0) { xyr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); (x1, y1, r1) = (xyr[0], xyr[1], xyr[2]); (x2, y2, r2) = (xyr[3], x.. 2023. 3. 7.
백준 18870 C#) 좌표 압축 요약하자면, 주어진 숫자가 몇번째로 작은지를 출력하는 문제이다. class Program { static void Main() { StreamWriter sw = new(new BufferedStream(Console.OpenStandardOutput())); //입력 int n = int.Parse(Console.ReadLine()); string[] x = Console.ReadLine().Split(); //압축된 좌표를 기존 위치에 출력하려면 기존 위치를 기억해야 하므로, //입력받은 x(num)를 기존 위치(oldIdx)와 함께 ValueTuple로 묶어 저장한다(input) (int num, int oldIdx)[] input = new (int, int)[n]; for (int i = 0; .. 2022. 12. 30.
백준 11651 C#) 좌표 정렬하기 2 이전 문제처럼 ValueTuple을 사용해서 풀어보자. *IComparable, IComparer에 대해 모른다면 이 글을 먼저 읽어보자. IComparer.Compare(T, T) 메서드 (System.Collections.Generic) 두 개체를 비교하여 한 개체가 다른 개체보다 작거나, 같거나 또는 크다는 것을 나타내는 값을 반환합니다. learn.microsoft.com 이 문제는 11650번 문제와 동일한 오름차순 정렬이지만 x가 아닌 y를 우선시하고 있다. 따라서 Compare 메서드는 아래의 기준으로 작성할 수 있다. 1) y가 같다면 x를 기준으로 정렬하라 2) y가 다르다면 y를 기준으로 정렬하라 반환값은 뺄셈으로 쉽게 구할 수 있다. 2022. 10. 12.
백준 11650 C#) 좌표 정렬하기 ValueTuple을 활용하면 쉽게 풀 수 있다. public static class PS { public static void Main() { StreamWriter sw = new(new BufferedStream(Console.OpenStandardOutput())); int n = int.Parse(Console.ReadLine()); (int x, int y)[] arr = new (int x, int y)[n]; string[] xy; for (int i = 0; i < n; i++) { xy = Console.ReadLine().Split(); arr[i] = (int.Parse(xy[0]), int.Parse(xy[1])); } Array.Sort(arr); for (int i = 0; i.. 2022. 10. 12.
백준 1436 C#) 영화감독 숌 또다시 각 자릿수를 추출하는 문제가 등장했다. public static class PS { public static void Main() { int n = int.Parse(Console.ReadLine()); int num = 666; int cnt = 0; while (true) { if (Check(num)) { if (++cnt == n) { Console.Write(num); return; } num += 1; } else { num += 3; } } } private static bool Check(int num) { int combo = 0; int digit; while (num > 0) { digit = num % 10; num /= 10; if (digit == 6) { if (++co.. 2022. 5. 28.
백준 1018 C#) 체스판 다시 칠하기 구현이 조금 까다로울 수도 있는 문제다. public static class PS { private static int m, n; private static char[][] board; static PS() { string[] mn = Console.ReadLine().Split(); m = int.Parse(mn[0]); n = int.Parse(mn[1]); board = new char[m][]; for (int i = 0; i < m; i++) { board[i] = Console.ReadLine().ToCharArray(); } } public static void Main() { int min = 32; for (int row = 0; row 2022. 5. 27.