목록Computer/Coding Test (70)
Machineboy空
Mine) - 규칙에 부합하는 숫자 리스트 미리 생성 - n: index값으로 사용 한계) 계산 횟수도 많고, n값 커지면 대응하지 못함 using System; using System.Collections.Generic; public class Solution { public int solution(int n) { int answer = 0; List arr = new List(); for (int i = 1; i < 200; i++) { if (i % 3 != 0 && !i.ToString().Contains("3")) { arr.Add(i); } } arr.Sort(); answer = arr[n-1]; return answer; } } 다른 사람 풀이) - n: 반복 횟수로 사용 using Sys..
https://www.acmicpc.net/problem/1260 1260번: DFS와 BFS 첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. 다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사 www.acmicpc.net 문제요약 DFS와 BFS로 각 탐색 순서 출력 난이도 Silver 2 풀이 포인트 1차원 DFS, BFS 정직한 구현 REVIEW 테스트 케이스는 통과했으나, 제출하니 오답이 떴다. 무엇을 놓쳤나 모범코드와 비교해보니 반복 범위를 잘못 설정했다. 문제 범위 1 v; for (int i = 0; i > a >> b; // 1. DF..
import sys sys.setrecursionlimit(10000) input = sys.stdin.readline n,m = map(int, input().split()) #_를 쓰는 이유: i에 관해 반복한다? 할 때 그 인덱스의 의미가 없고, 반복 횟수 만이 의미가 있을 때 A = [[] for _ in range(n+1)] #N개의 노드만큼의 인접 리스트를 만들어 둔다. visited = [False] * (n+1) #방문리스트 n개 또한 만들어 둔다. def DFS(v): # DFS(깊이우선탐색) 함수 정의 visited[v] = True # 방문리스트 값이 True면 반환, False면 DFS 재귀함수 호출 for i in A[v]: if not visited[i]: DFS(i) for _..
class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Queue myQueue = new Queue(); for (int i = 1; i 1) { myQueue.Dequeue(); myQueue.Enqueue(myQueue.Dequeue()); } Console.WriteLine(myQueue.Peek()); } } from collections import deque N = int(input()) myQueue = deque() for i in range(1,N+1): myQueue.append(i) while len(myQueue) >1: myQueue.popleft() myQueue.append..
N의 범위가 1000이하로 매우 작기 때문에 n2^시간 복잡도 알고리즘으로 풀 수 있다. N = int(input()) A = [0] * N for i in range(N): A[i] = int(input()) for i in range(N-1): for j in range(N-1-i): if A[j] > A[j+1]: temp = A[j] A[j] = A[j+1] A[j+1] = temp for i in range(N): print(A[i])
from queue import PriorityQueue import sys print = sys.stdout.write input = sys.stdin.readline N = int(input()) myQueue = PriorityQueue() for i in range(N): request = int(input()) if request == 0: if myQueue.empty(): print('0\n') else: temp = myQueue.get() print(str((temp[1]))+'\n') else: myQueue.put((abs(request),request))
#오답 whole, part = map(int, input().split()) DNA = str(input()) A,C,G,T = map(int, input().split()) Acount = 0 Ccount = 0 Gcount = 0 Tcount = 0 AvailableCount = 0 for i in range(whole-part): k = i + part for k in range(part+k): if DNA[i]=="A": Acount +=1 elif DNA[i]=="C": Ccount +=1 elif DNA[i]=="G": Gcount +=1 elif DNA[i]=="T": Tcount +=1 if Acount >= A and Ccount >=C and Gcount >=G and Tcount >..