본문 바로가기
반응형

알고리즘38

[백준/Python] 1747번 소수&팰린드롬 문제https://www.acmicpc.net/problem/1747소스코드def primeCheck(data): if data == 1: return False for i in range(2, int(data ** 0.5) + 1): if data % i == 0: return False return Truedef palindromeCheck(data): data = str(data) if data == data[::-1]: return True else: return False n = int(input())while True: if primeCheck(n) and palindrome.. 2024. 10. 4.
[백준 / Python] 14698번 전생했더니 슬라임 연구자였던 건에 대하여 (Hard) 문제https://www.acmicpc.net/problem/14698소스코드import heapqimport sysinput = sys.stdin.readlineT= int(input())for i in range(T): N = int(input()) ls = list(map(int, input().split())) heapq.heapify(ls) answer = 1 while len(ls) > 1: a = heapq.heappop(ls) b = heapq.heappop(ls) c = a * b answer *= c heapq.heappush(ls, c) print(answer % 1000000007) 우선순.. 2024. 9. 23.
[백준 / Python] 17298번 오큰수 문제 https://www.acmicpc.net/problem/17298  소스코드from collections import dequeN = int(input())ls = list(map(int, input().split()))deque = deque()answer = [-1] * Ndeque.append(0)for i in range(1, N): # while deque and ls[deque[-1]]  이 문제에서는 스택을 사용한다. 소스코드에서 스택에 넣어지는 데이터는 값이 아니라 index이라는 것에 주의한다.  스택에 먼저 0을 삽입한다. 1부터 n-1까지 순회를 돈다. ( i in range(1, n) )  - 여기서 ls[i] 를 스택의 꼭대기의 오큰수인지 판단할 것이다. - 만약 스.. 2024. 9. 19.
[백준 / Python] 11000번 강의실 배정 문제https://www.acmicpc.net/problem/11000  코드import heapq# 3# 1 3# 2 4# 3 5heap = []# heapq.heappush(heap, 50)# heapq.heappush(heap, 10)# heapq.heappush(heap, 20)n = int(input())datalist = []size = 0for i in range(n): datalist.append(tuple(map(int, input().split())))datalist.sort(key=lambda x : (x[0]))# print(datalist)# data (int, int)for data in datalist: if len(heap) > 0: if heap[0].. 2024. 5. 29.
[백준 / Python] 14370번 전화번호 수수께끼 (Large) 문제https://www.acmicpc.net/problem/14370코드import sysinput = sys.stdin.readline n = int(input())data = { 'A':0, 'B':0, 'C':0, 'D':0, 'E':0, 'F':0, 'G':0, 'H':0, 'I':0, 'J':0, 'K':0, 'L':0, 'M':0, 'N':0, 'O':0, 'P':0, 'Q':0, 'R':0, 'S':0, 'T':0, 'U':0, 'V':0, 'W':0, 'X':0, 'Y':0, 'Z':0}for i in range(n): answerlist = [.. 2024. 5. 16.
[백준 / Python] 7576번 토마토 문제https://www.acmicpc.net/problem/7576https://www.acmicpc.net/problem/7576 풀이#2차원 dfs / / replit.comfrom collections import deque# append():- This function is used to insert the value in its argument to the right end of the deque.# appendleft():- This function is used to insert the value in its argument to the left end of the deque.# pop():- This function is used to delete an argument from th.. 2024. 5. 8.
[백준 / Python] 1015번 수열 정렬 문제 https://www.acmicpc.net/problem/1015 1015번: 수열 정렬 P[0], P[1], ...., P[N-1]은 0부터 N-1까지(포함)의 수를 한 번씩 포함하고 있는 수열이다. 수열 P를 길이가 N인 배열 A에 적용하면 길이가 N인 배열 B가 된다. 적용하는 방법은 B[P[i]] = A[i]이다. 배열 A가 주 www.acmicpc.net 풀이 n = int(input()) data = list(map(int, input().split())) sortdata = sorted(data) answer = [0] * n for i in range(n): answer[i] = sortdata.index(data[i]) sortdata[sortdata.index(data[i])] =.. 2024. 3. 28.
[백준/Python] 17219번 비밀번호 찾기 문제 https://www.acmicpc.net/problem/17219 17219번: 비밀번호 찾기 첫째 줄에 저장된 사이트 주소의 수 N(1 ≤ N ≤ 100,000)과 비밀번호를 찾으려는 사이트 주소의 수 M(1 ≤ M ≤ 100,000)이 주어진다. 두번째 줄부터 N개의 줄에 걸쳐 각 줄에 사이트 주소와 비밀번 www.acmicpc.net 풀이 import sys N, M = map(int, input().split()) passwd = {} for i in range(N): a = sys.stdin.readline().rstrip().split() passwd[a[0]] = a[1] for i in range(M): a = sys.stdin.readline().rstrip() print(pass.. 2024. 2. 27.
[백준/Python] 9659번 돌 게임 5 문제 [백준/Python] 9659번 돌 게임 5 https://www.acmicpc.net/problem/9659 9659번: 돌 게임 5 첫째 줄에 N이 주어진다. (1 ≤ N ≤ 1,000,000,000,000) www.acmicpc.net 소스코드 n = int(input()) if n % 2 == 1: print('SK') else: print('CY') 게임을 계산해보면 n이 홀수일때는 상근(SK)이 승리하고, 짝수일때는 창영(CY)가 승리하는 패턴을 찾을 수 있습니다. 2024. 2. 22.
[백준 / Python] 7569번 토마토 문제 https://www.acmicpc.net/problem/7569 7569번: 토마토 첫 줄에는 상자의 크기를 나타내는 두 정수 M,N과 쌓아올려지는 상자의 수를 나타내는 H가 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M ≤ 100, 2 ≤ N ≤ 100, www.acmicpc.net 소스코드 #3차원 dfs / / replit.com from collections import deque # append():- This function is used to insert the value in its argument to the right end of the deque. # appendleft():- This function is used to inse.. 2024. 2. 17.
728x90
반응형