본문 바로가기
반응형

알고리즘149

(Python/🥈3)백준 알고리즘 2606번: 바이러스 문제출처: https://www.acmicpc.net/problem/2606 2606번: 바이러스 첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어 www.acmicpc.net 풀이: bfs 형식 import sys from collections import deque sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') computer = int(input()) line = int(input()) graph = [[] for _ in range(computer+1)] for i in range(line.. 2023. 2. 13.
(Python/🥈1)백준알고리즘1629번:곱셈 문제 출처: https://www.acmicpc.net/problem/1629 1629번: 곱셈 첫째 줄에 A, B, C가 빈 칸을 사이에 두고 순서대로 주어진다. A, B, C는 모두 2,147,483,647 이하의 자연수이다. www.acmicpc.net 풀이: import sys def func(A,B,C): if B == 1: return A % C else: half = func(A, B//2, C) if B % 2 == 0: # 짝수면 return half * half % C else: return half * half * A % C A,B,C =map(int,(input().split())) print(func(A,B,C)) 일단 예를들어서 ABC에 2 16 12 가 들어왔다고 생각을하면 2.. 2022. 12. 20.
(Python/🥈1)백준알고리즘 1074번:Z 문제출처:https://www.acmicpc.net/problem/1074 문제풀이: import sys sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') def func(n,r,c): if n == 1: return 2 * r + c half = (2**n)//2 if r = half: return half * half + func(n-1, r, c-half) elif r >= half & c < half: return 2 * half * half + func(n-1, r-half, c) else: return.. 2022. 12. 20.
(Python/🥈1)백준 알고리즘 14888번: 연산자 끼워넣기 문제 출처: https://www.acmicpc.net/problem/14888 14888번: 연산자 끼워넣기 첫째 줄에 수의 개수 N(2 ≤ N ≤ 11)가 주어진다. 둘째 줄에는 A1, A2, ..., AN이 주어진다. (1 ≤ Ai ≤ 100) 셋째 줄에는 합이 N-1인 4개의 정수가 주어지는데, 차례대로 덧셈(+)의 개수, 뺄셈(-)의 개수, www.acmicpc.net 풀이: import sys N = int(input()) number = list(map(int,input().split())) op = list(map(int,input().split())) max_res, min_res = -sys.maxsize -1, sys.maxsize def solution(num,idx,a,b,c,d).. 2022. 12. 5.
(Python/🏅4)백준 알고리즘 9663번: N-Queen 문제 출처: 풀이: 유튜버에서 강좌보고 배운 코드 >> 시간초과가 나온다. import sys sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') N =int(input()) col = [0] * (N+1) count =0 def N_Queen(col, i): n =len(col) -1 if promising(col, i): if i == n: global count count += 1 else: for j in range(1, n+1): # 다음 행 체크하려고 (1,3) 왔을때 2,1 / 2,2/ 2,3/ 2,4 체크 col[i+1] = j # 다음행 추가(1,3,1)\/ (1,3,2) 이런식 N_Queen(col,i+1) def prom.. 2022. 11. 21.
(Python/🥈2)백준 알고리즘 15665번: N과 M(10) 문제 출처: https://www.acmicpc.net/problem/15664 15664번: N과 M (10) 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해 www.acmicpc.net 풀이: import sys sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') n,m = map(int,input().split()) x =sorted(list(map(int,input().split()))) visited = [False] * n result = [] def bt(): if len(result) ==.. 2022. 11. 20.
반응형