본문 바로가기

Problem Solving/SWEA20

[ SWEA ] D3 - 1217, 1230, 3431, 4406 - python 문제풀이 1217 거듭제곱 def mul(num,k): global n,cnt num *= n if k == cnt: return num return mul(num,k+1) for tc in range(10): N = int(input()) n,cnt = map(int, input().split()) print("#{} {}".format(N,mul(1,1))) 또 다른 방식 def mul(n,m): if m == 1: return n return mul(n,m-1)*n for tc in range(10): a = int(input()) b,c = map(int, input().split()) print('#{} {}'.format(a,mul(b,c))) 1230 암호문3 오래 걸리지만, 문제를 잘 이해하고 차근.. 2021. 6. 29.
[ SWEA ] D2 - 1940, 1928, 1288, 1284, 1204 - python 문제풀이 1940 가랏 RC카 접근법 : 커맨드가 0이 아닐 경우에만 뭔가 계산을 해주고, 0일때는 바로 현재 속도만 더해주면 된다 for tc in range(int(input())): commands = int(input()) distance = 0 current_speed = 0 for _ in range(commands): info = input() if info != "0": #앞에서 1인지2인지도 비교안하고 빠질수있음 command = info.split(" ")[0] acceleration = int(info.split(" ")[1]) if command == "2" and current_speed < acceleration: current_speed = 0 elif command == "2": cu.. 2021. 6. 28.
[ SWEA ] D2 - 1954, 1948, 1946, 1945 - python 문제풀이 1954 달팽이 숫자 달팽이처럼 돌기 위해서는 오른쪽, 아래, 왼쪽, 위쪽 방향을 반복적으로 돌아가면서 이동해 들어가고, 그 빈도는 위 그림에서 볼 수 있듯이 각 n번에서 1번 순서대로, 처음을 제외하면 각각 2번씩 반복적이라는 규칙을 찾을 수 있다. for tc in range(int(input())): N = int(input()) snail = [[0]*N for _ in range(N)] number = 1 jump_cnt = N direction = 'right' # 'right','down','left','up'순으로 바뀔 것 row_idx,col_idx = 0,0 while number 2021. 6. 27.
[ SWEA ] D2 - 1970, 1966, 1961, 1959 - python 문제풀이 1970 쉬운 거스름돈 지불할 수 있는 돈의 종류(option)들을 순회하면서, 최대한 낼 수 있는 개수만큼 쓰고 다음 단위(더 작은 지불 단위 옵션)으로 넘어가게 해서 풀 수 있음 options = [50000,10000,5000,1000,500,100,50,10] for tc in range(int(input())): N = int(input()) cnt = [0]*8 for i in range(8): if N != 0: cnt[i] += N//options[i] N %= options[i] else: break print("#{}\n{}".format(tc+1, " ".join(map(str,cnt)))) 1966 숫자를 정렬하자 방법 1 - sort 함수 사용 방법 2 - 개수를 세어나갈 카운트 .. 2021. 6. 26.
[ SWEA ] D2 - 1983, 1979, 1976, 1974 - python 문제풀이 1983 조교의 성적매기기 scores = ["A+","A0","A-","B+","B0","B-","C+","C0","C-","D"] for tc in range(int(input())): N,K = map(int, input().split()) # i번째 점수는 (i+1)번 학생의 점수 info = [list(map(int, input().split())) for _ in range(N)] student_scores = [] for i in range(N): total = info[i][0]*0.35 + info[i][1]*0.45 + info[i][2]*0.2 student_scores.append([total, (i+1)]) student_scores.sort(key=lambda x:x[0],rev.. 2021. 6. 24.
[ SWEA ] D2 - 2001, 1989, 1986, 1984 - python 문제풀이 2001 파리퇴치 퇴치할 파리 정사각형이 어디까지 이동할 수 있을 지 파악해서 갈 수 있는 곳 까지만 for문을 도는게 그나마 시간을 조금이라도 줄이는 방법 for tc in range(int(input())): N,M = map(int, input().split()) fly = [list(map(int, input().split())) for _ in range(N)] max_value = 0 for i in range(N-M+1): for j in range(N-M+1): row_idx = i col_idx = j tmp = 0 for k in range(M): tmp += sum(fly[row_idx+k][col_idx:col_idx+M]) if tmp > max_value: max_value = .. 2021. 6. 24.
[ SWEA ] D2 - 1859, 1926, 2007, 2005 - python 문제풀이 1859 백만장자프로젝트 문제를 먼저 잘 이해하고 생각한 뒤 풀면 생각보다 쉽게 풀리는 문제 Idea 1. 일단, 최대의 이익을 내려면 계속 사다가 가장 비싸게 팔 수 있는 시점에 팔아야 한다. Idea 2. 배열을 뒤에서 부터 순회하면서, 특정 시점에서 얼마에 파는게 가장 최대일지 구하면 된다 - 제일 마지막 순간에 팔 수 있는 가격을 초기값으로 설정 - 뒤에서부터 오면서, 더 비싸게 팔 수 있는 순간이 올 경우(t2) 최대값으로 가격을 갱신해주기 - 더 비싸게 팔 수 있는 순간이 아니라면, 사는게 무조건 이득임 for tc in range(int(input())): N = int(input()) data = list(map(int, input().split())) max_value = 0 curmax.. 2021. 6. 24.
[ SWEA ] D1 풀이 모음 - python 2072 홀수만 더하기 for tc in range(int(input())): a = list(map(int, input().split())) s = 0 for i in range(10): if a[i]%2!=0: s += a[i] print("#{} {}".format(tc+1, s)) 2071 평균값구하기 for tc in range(int(input())): a = list(map(int, input().split())) print("#{} {}".format(tc+1, round(sum(a)/10))) 2070 큰놈,작은놈,같은놈 for tc in range(int(input())): a,b = map(int, input().split()) print("#{} ".format(tc+1), end=.. 2021. 6. 23.