-
[백준] 1913 달팽이ALGORITHM/BOJ 2021. 9. 29. 23:32
https://www.acmicpc.net/problem/1913
2021-09-27
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main1913 {public static void main(String[] args) throws IOException {BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer(bf.readLine().trim());int N = Integer.parseInt(st.nextToken());st = new StringTokenizer(bf.readLine().trim());int M = Integer.parseInt(st.nextToken());int[][] arr = new int[N][N];int num = N*N;for(int p = 0; p < N/2; p++) {for(int i = p; i < N-p; i++) { // downarr[i][p] = num--;}for(int i = p+1; i < N-p; i++) { // rightarr[N-p-1][i] = num--;}for(int i = N-p-2; i >= p; i--) { // uparr[i][N-p-1] = num--;}for(int i = N-p-2; i > p; i--) { // left;arr[p][i] = num--;}}arr[N/2][N/2] = 1;StringBuilder sb = new StringBuilder();StringBuilder ans = new StringBuilder();for(int i = 0; i < N; i++) {for(int j = 0; j < N; j++) {sb.append(arr[i][j]).append(" ");if(arr[i][j] == M) ans.append(i+1).append(" ").append(j+1);}if(i != N-1) sb.append("\n");}System.out.println(sb.toString());System.out.println(ans.toString());}}cs #문제풀이
구현
'ALGORITHM > BOJ' 카테고리의 다른 글
[백준] 2941 크로아티아 알파벳 (0) 2021.11.08 [백준] 2467 용액 (0) 2021.11.02 [백준] 10816 숫자 카드 2 (0) 2021.09.29 [백준] 1992 쿼드트리 (0) 2021.09.29 [백준] 2470 두 용액 (0) 2021.09.26