본문 바로가기
반응형

코딩테스트 준비/백준 C#167

C# - 1966 +) 풀이 기본 셋팅 01 Queue 생성 Tuple의 첫번째 요소에는 index값 두번째 요소에는 중요도를 담는다. Queue queue = new Queue(); int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); for (int i = 0; i < N; i++) { queue.Enqueue(new Tuple(i, input[i])); } 02 input.Sort() 중요도를 오름차순으로 정렬한다. Array.Sort(input); 03 하나씩 꺼내기 Tuple firstitem = queue.Dequeue(); 주요 알고리즘 01 만약 firstitem이 현재의 제일 큰 중요도와 같을 경우 현재 중요도는 그럼 dequeue됐으니까 다음.. 2024. 3. 17.
백준 C# - 11286 +) 눈물의 풀이 들어가기 앞서 풀다가 못풀겠어서 힌트를 찾아봤는데 C#으로된 정답 코드가 없었다.. Phthon으로 된 코드는 heapq을 이용해서 코드가 간단한데 C#은 없다 눈물.. 그래서 6시간정도 걸렸다. 하핳.. 그래도 통과돼서 뿌듯하다 실패 01 Sort 사용 첫번째로 풀었을때 Sort를 이용해서 풀었는데 2%에서 시간초과가 떴다. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { public static void Main() { List pq = new List(); int n = int.Parse(Console.ReadLine()); for(i.. 2024. 3. 17.
백준 C# - 1987 풀다보니 백트래킹 문제였다. 풀다보니 헷갈린게 있어서 버벅거렸다 하핳.. 아래 링크에 있는 알고리즘의 큰 맥란이 매우 비슷하다! 알고리즘에 대한 자세한 설명은 아래 게시글에 있다. 백준 C# - 15649 +) 풀이 대표적인 백트래킹 문제이다. 백트래킹 모든 경우의 수를 탐색하며 더 이상 해가 나올 것 같지 않으면 이전으로 돌아가서 다른 경우를 탐색한다. 풀이 원래 알던 DFS 알고리즘에서는 visited[i] = tru code-piggy.tistory.com 코드 전문 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static char.. 2024. 3. 12.
백준 C# - 11725 +) 풀이 문제를 읽고 일단 그려봐야겠다는 생각이 들어서 그려보았다. 7 1 6 6 3 3 5 4 1 2 4 4 7 각 노드의 부모 노드 번호 그린 후 어느 알고리즘을 사용할까 하다가 DFS를 사용하기로 했다. 01 DFS 알고리즘 선택된 노드에서는 방문했다고 표시를 하고 부모노드를 기입하도록 하였다. public static void DFS(int node) { visited[node] = true; foreach (int neighbor in graph[node]) { if (!visited[neighbor]) { parent[neighbor] = node; DFS(neighbor); } } } 02 그래프 생성 int N = int.Parse(Console.ReadLine()); graph = new List.. 2024. 3. 4.
백준 C# - 1620 +) 풀이 이 문제를 풀기 앞서 할 수 있어야 하는 2가지 01 Dictionary에서 value이용해서 Key값 가져오는 법 Dictionary dic = new Dictionary(); var keys = new List(dic.Keys); string key = keys[4]; 02 Dictionary에서 Key값 이용해서 Value값 가져오는 법 string keyToFind = "piggy"; string value = dict[keyToFind]; 코드 전문 using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { public static void Main() { string[] t.. 2024. 2. 24.
백준 C# - 7785 코드 전문 using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); Dictionary ht = new Dictionary(); StringBuilder sb = new StringBuilder(); for(int i = 0; i< n;i++) { string[] token = Console.ReadLine().Split(); if(ht.ContainsKey(token[0])) ht.Remove(token[0]); else ht.Add(token[0], token[.. 2024. 2. 24.
반응형