본문 바로가기
728x90

코딩테스트77

[python] 백준 13904번: 과제 https://www.acmicpc.net/problem/13904 13904번: 과제 예제에서 다섯 번째, 네 번째, 두 번째, 첫 번째, 일곱 번째 과제 순으로 수행하고, 세 번째, 여섯 번째 과제를 포기하면 185점을 얻을 수 있다. www.acmicpc.net # 참고블로그 https://whitehairhan.tistory.com/337 https://velog.io/@heyksw/Python-%EB%B0%B1%EC%A4%80-gold-13904-%EA%B3%BC%EC%A0%9C 문제가 처음 읽었을 때 쉽게 이해가 되지 않았다. 그래서 블로그를 참고하면서 풀었다. 결론적으로 뒤에서 부터 가능한 과제를 그리디 방법으로 풀면 되는 문제였다. 이 문제의 경우 푸는 방법이 그리디말고도 우선순위 큐로 푸.. 2023. 1. 8.
[python] 백준 14567번: 선수과목 https://www.acmicpc.net/problem/1654 1654번: 랜선 자르기 첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import sys def binary_search(array,target,start,end): while start 2023. 1. 6.
[python] Level2_바이러스 https://softeer.ai/practice/info.do?idx=1&eid=407&sw_prbl_sbms_sn=117912 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 이 문제는 좀 짚고 넘어가야 하는게 있습니다. 단순한 거듭제곱에 대한 문제인데 for 문이나 pow함수로 거듭제곱을 표현한다면 시간복잡도가 O(n)이 됩니다. 이를 해결하기 위해서는 pow함수 자체를 알아보았다. - pow함수 자체에 대한 개념 https://deok2kim.tistory.com/88 [python] pow, 제곱, 거듭제곱과 나머지 📗 파이썬에서 거듭제곱과 나머지를 구할 때! 속도 차이 🔵 pow(a,b) vs a**b 100의 100승을 구할 때 입력 방법 속도 100**1.. 2023. 1. 4.
[python] Level2_GBC https://softeer.ai/practice/info.do?idx=1&eid=584&sw_prbl_sbms_sn=117856 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 import sys # sys.stdin = open("input3.txt",'r') n,m = map(int,sys.stdin.readline().split()) #빈 딕셔너리 생성 n_dict .. 2023. 1. 4.
[python] Level2_회의실 예약 https://softeer.ai/practice/info.do?idx=1&eid=626 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 import sys #sys.stdin = open("input1.txt","r") # n:회의실 수, m:예약된 회의의 수 n,m = map(int,sys... 2023. 1. 3.
[python] Level2_비밀 메뉴 https://softeer.ai/practice/info.do?idx=1&eid=623&sw_prbl_sbms_sn=116899 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import sys #sys.stdin = open("input.txt","r") # m:정답, n: 숫자열, k: k이하 정수 m,n,k = map(int,input().split()) m_array = list(map(int,input().split())) n_array = list(map(int,input().split())) #print(m_array,n_array) if len(.. 2023. 1. 3.
[python] Level2_지도 자동 구축 https://softeer.ai/practice/result.do?eventIdx=1&submissionSn=SW_PRBL_SBMS_116035&psProblemId=413 https://softeer.ai/practice/result.do?eventIdx=1&psProblemId=413&submissionSn=SW_PRBL_SBMS_116035 softeer.ai 1 2 3 4 5 6 7 8 9 10 11 import sys #sys.stdin = open("input2.txt",'r') #4,9,25,81 #2제곱, 3제곱 5제곱 9제곱 #2,3,5,9 #2^(n-1)+1 n = int(input()) answer = (2**n+1)**2 print(answer) cs 2023. 1. 1.
[python] Level2_8단 변속기 https://softeer.ai/practice/info.do?idx=1&eid=408 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 5 6 7 8 9 10 11 import sys # 입력변수를 받기 array = list(map(int,sys.stdin.readline().split())) if array == [1,2,3,4,5,6,7,8]: print("ascending") elif array == [8,7,6,5,4,3,2,1]: print("descending") else: print("mixed") Colored by Color Scripter cs 2023. 1. 1.
[python] Level2_장애물 인식 프로그램 https://softeer.ai/practice/info.do?idx=1&eid=409 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 import sys # 정사각형 n개 갯수받기 #sys.stdin = open("input1.txt","r") n = int(sys.stdin.readline()) # map 정보 저장 graph = [] for i in range(n): graph.append(list(map(int,input()))) # 모든 경로에 대해 탐색해야 하므.. 2023. 1. 1.
[python] Level1_A+B https://softeer.ai/practice/info.do?idx=1&eid=362 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 cnt = int(input()) for i in range(1,cnt+1): a,b = map(int,input().split()) print(f"Case #{i}: {a+b}") cs 2023. 1. 1.
[python] Level1_최단거리 https://softeer.ai/practice/info.do?idx=1&eid=990 Softeer 연습문제를 담을 Set을 선택해주세요. 취소 확인 softeer.ai 1 2 3 4 5 6 7 count = 0 for i in range(5): n,m = map(str,input().split()) na, nb = map(int, n.split(":")) ma, mb = map(int, m.split(":")) count += (ma*60+mb)-(na*60+nb) print(count) cs 2022. 12. 31.
1217. [S/W 문제해결 기본] 4일차 - 거듭 제곱 https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV14dUIaAAUCFAYD&categoryId=AV14dUIaAAUCFAYD&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=3 SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def mul(n,m): global count if m .. 2022. 11. 19.
1249. [S/W 문제해결 응용] 4일차 - 보급로 https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=4&contestProbId=AV15QRX6APsCFAYD&categoryId=AV15QRX6APsCFAYD&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=ALL&select-1=4&pageSize=10&pageIndex=1 SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com -dfs 풀이 이렇게 풀면 시간 초과가 나와서 bfs로 다시 풀었습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 .. 2022. 11. 19.
14567번: 선수과목 https://www.acmicpc.net/problem/14567 14567번: 선수과목 (Prerequisite) 3개의 과목이 있고, 2번 과목을 이수하기 위해서는 1번 과목을 이수해야 하고, 3번 과목을 이수하기 위해서는 2번 과목을 이수해야 한다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 n,m = map(int,input().split()) #dp값은 최소 몇학기 인지 dp = [1] * (n) #인덱스번호가 과목번호, 안에 든 값들은 선수과목 번호 array = [[]for i in range(n)] for i in range(m): a, b = map(int,input().split()) array[b-1].. 2022. 11. 18.
21312번 홀짝 칵테일 https://www.acmicpc.net/problem/21312 21312번: 홀짝 칵테일 정진이는 특별한 음료를 가지고 있다. 음료들은 정수로 표현되는 고유 번호를 가지고 있다. 정진이는 이 음료들을 섞어 만든 칵테일을 만든다. 이 칵테일은 홀짝 칵테일이라 부르는데, 홀짝 칵 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #a,b,c를 리스트로 저장 array = list(map(int,input().split())) #곱한값들 저장할 빈 리스트 count = [] #가능한 모든 수 for i in range(3): count.append(array[i]) for i in range(3): if i .. 2022. 11. 18.
728x90