SWEA 63

swea 4615 [D3] 재미있는 오셀로 게임 JAVA

풀이 : dx, dy를 활용해서 8방향으로 움직이면서 if 문을 활용해 게임 판 내에 있는지 확인. 상대방 돌을 뒤집을 수 있으면 뒤집음 Code public class Solution4615 { static int N;// 보드 한변의 길이 (4, 6, 8 중 하나) static int M;// 플레이어가 돌을 놓는 횟수 // 상, 하, 좌, 우, 좌상, 우하, 우상, 좌하 static final int[] dx = { -1, 1, 0, 0, -1, 1, -1, 1 }; static final int[] dy = { 0, 0, -1, 1, -1, 1, 1, -1 }; static int[][] map; public static void main(String[] args) throws Exception ..

SWEA 2023.11.29

swea 3307 [D3] 최장 증가 부분 수열 JAVA

풀이 : DP로 해결해야 함 -> N (1 ≤ N ≤ 1,000) dp 배열을 만들고 그떄의 최대 길이를 저장하면서 max를 갱신해야함. ( dp를 쓰면, 이전에 했던 최대 길이 구하는 과정을 중복 안할 수 있음 ) Code public class Solution3307 { static int[] arr; static int[] dp; static int max, N; public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int tc = 1; tc

SWEA 2023.11.29

swea 2806 [D3] N-Queen JAVA

풀이 : DFS로 풀어야 함. board[N]을 만들어 열을 내려가면서 해당 행에 어떤 위치에 퀸을 놓았는지 명시. 재귀 호출을 통해 위쪽 열(curr = 0)부터 퀸을 놓고 아래로(curr = N) 내려가는 방식 Code public class Solution2806V { static int board[]; // 퀸의 위치를 담는다. (board[0]=1 -> (0,1)에 하나의 퀸이 있다. board[1] = 3 -> (1,3)에 하나의 퀸이 있다.) static int answer; public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(i..

SWEA 2023.11.29

swea 1873 [D3] 상호의 배틀필드 JAVA

풀이 : dx, dy, dir 이용 switch문 또는 if문으로 문자에 따른(방향) dir를 바꿔줌 Code public class Solution1873 { static int T, H, W, x, y, dir; static char[][] map; static int[][] v = {{0,0}, {0,1}, {0,-1}, {1,0}, {-1,0}}; // 동서남북 public static void main(String[] args) { Scanner sc = new Scanner(System.in); T = sc.nextInt(); for(int tc=1; tc= H || ny >= W) { break; // 포탄이 맵 밖으로 나갔을 때 } if (board[nx][ny] == '#') { brea..

SWEA 2023.11.24

swea 1860 [D3] 진기의 최고급 붕어빵 JAVA

방법 1 : 1초씩 증가시켜서 M초 나누어서 K개의 빵을 증가, 줄 수 있는 빵이 있는지 판별 방법 2 : M초씩 증가시키면서 M초 전에 손님이 왔는지 판별, 있다면 빵을 줄 수 있는지 판별 Code public class Solution1860 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int tc = 1; tc 생각 못하면 틀림 for (int i = 1; i 0) bread--; else { // 줄 빵이 없으므로 종료 possible = false; break; } } } } if (possible) result = "Possible"; System...

SWEA 2023.11.24
1 2 3 4 5 ··· 7