재귀, 정렬 알고리즘
하노이탑 def hanoi(n,fr,tmp,to): if n == 1: print("원반 1을 %s에서 %s로" %(fr, to)) else: #n-1개를 시작점에서 임시 지점으로 옮기기 hanoi(n-1,fr,to,tmp) #남은 1개를 목적지로 print("원판 %d를 %s에서 %s로"%(n,fr,to)) #임시 지점에 있는 n-1개를 목적지로 hanoi(n-1,tmp,fr,to) hanoi(4, 'A', 'B', 'C') 거듭제곱 def pow(x,n): if n == 0 : return 1; elif n % 2 == 0: return pow(x*x, n//2) else: return x*pow(x*x, (n-1)//2) print(pow(2,4)) print(pow(2,5)) 피보나치 순환 def..
2023. 9. 8.
섬나라 아일랜드(BFS)
풀이에 Pointer 클래스를 사용한 것 이외에는 거의 비슷하다 import java.util.*; class Pointer{ int x; int y; Pointer(int x, int y){ this.x = x; this.y = y; } } class Main{ static int[] dx = {-1,0,1,0,-1,-1,1,1}; static int[] dy = {0,1,0,-1,-1,1,1,-1}; static int[][] board; static Queue Q = new LinkedList(); static int res = 0, n; public void Solution(){ for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (boar..
2023. 9. 3.