전체 글
N과 M (3) 풀이
문제 링크: https://www.acmicpc.net/problem/15651 백준 알고리즘 기초 2/2 510에서 3번째 - 15651번 N과 M (3)를 풀어보았다. 풀이: 파이썬의 경우 product을 이용했다. C++ Python from itertools import product n,m=map(int,input().split()) arr=[i+1 for i in range(n)] res=product(arr,repeat=m) for i in res: for j in i: print(j,end=' ') print() Java
N과 M (2) 풀이
문제 링크: https://www.acmicpc.net/problem/15650 백준 알고리즘 기초 2/2 510에서 2번째 - 15650번 N과 M (2)를 풀어보았다. 풀이: 파이썬의 경우 combinations을 이용했다. C++ Python from itertools import combinations n,m=map(int,input().split()) arr=[i+1 for i in range(n)] res=combinations(arr,m) for i in res: for j in i: print(j,end=' ') print() Java
N과 M (1) 풀이
문제 링크: https://www.acmicpc.net/problem/15649 백준 알고리즘 기초 2/2 510에서 1번째 - 15649번 N과 M (1)를 풀어보았다. 풀이: 파이썬의 경우 permutations을 이용했다. C++ Python from itertools import permutations n,m=map(int,input().split()) arr=[i+1 for i in range(n)] res=permutations(arr,m) for i in res: for j in i: print(j,end=' ') print() Java
수 이어 쓰기 1 풀이
문제 링크: https://www.acmicpc.net/problem/1748 백준 알고리즘 기초 2/2 500에서 7번째 - 1748번 수 이어 쓰기 1을 풀어보았다. 풀이: n을 입력이라고 했을 때, 1 자릿수는 n을, 2 자릿수는 2n-9를, 3 자릿수는 3n-99-9를 출력하는 규칙을 찾으면 된다. C++ Python n=input() inp=int(n) res=len(n)*inp for i in range(1,len(n)): res-=(10**i-1) print(res) Java
카잉 달력 풀이
문제 링크: https://www.acmicpc.net/problem/6064 백준 알고리즘 기초 2/2 500에서 6번째 - 6064번 카잉 달력을 풀어보았다. 풀이: 시간초과가 나서 https://ji-gwang.tistory.com/m/249 를 참고해 풀었다. C++ Python for i in range(int(input())): m,n,x,y=map(int,input().split()) k=x while 1: if k>m*n: print(-1) break if (k-x)%m==0 and (k-y)%n==0: print(k) break k+=m Java
테트로미노 풀이
문제 링크: https://www.acmicpc.net/problem/14500 백준 알고리즘 기초 2/2 500에서 5번째 - 14500번 테트로미노를 풀어보았다. 풀이: https://velog.io/@jajubal/%ED%8C%8C%EC%9D%B4%EC%8D%AC%EB%B0%B1%EC%A4%80-14500-%ED%85%8C%ED%8A%B8%EB%A1%9C%EB%AF%B8%EB%85%B8 를 참고했다. C++ Python def dfs(r,c,idx,total): global res if res>=total+maxs*(3-idx): return if idx==3: res=max(res,total) return else: for i in range(4): nr=r+dr[i] nc=c+dc[i] if 0
리모컨 풀이
문제 링크: https://www.acmicpc.net/problem/1107 백준 알고리즘 기초 2/2 500에서 4번째 - 1107번 리모컨을 풀어보았다. 풀이: https://jennnn.tistory.com/60 코드를 참고했다. C++ Python n=int(input()) m=int(input()) arr={str(i) for i in range(10)} if m!=0: arr-=set(input().split()) cnt=abs(100-n) for i in range(1000000): i=str(i) for j in range(len(i)): if i[j] not in arr: break elif j==len(i)-1: cnt=min(cnt,abs(int(i)-n)+len(i)) print(..
날짜 계산 풀이
문제 링크: https://www.acmicpc.net/problem/1476 백준 알고리즘 기초 2/2 500에서 3번째 - 1476번 날짜 계산을 풀어보았다. 풀이: e는 15로 나눴을 때 나머지이고, s는 28로 나눴을 때 나머지이고, m은 19로 나눴을 때 나머지다. 각자 0일 경우만 처리해 주면 된다. C++ Python e,s,m=map(int,input().split()) year=1 while True: anse=year%15 if anse==0: anse=15 anss=year%28 if anss==0: anss=28 ansm=year%19 if ansm==0: ansm=19 if anse==e and anss==s and ansm==m: break year+=1 print(year) J..