import java.util.Scanner;
 
 
class Solution {
    static int Answer;
 
    static int[][] map = new int[16][16]; // 행, 열
    static int[][] visited = new int[16][16]; // 행, 열
    static boolean findPath ;
     
    public static void main(String args[]) throws Exception {
         
         
        Scanner sc = new Scanner(System.in);
         
        for(int T=1; T <=10; T++) {
             
            // Test 번호
            sc.nextLine(); 
            int startX = -1, startY = -1;
             
            //map에 데이터 입력
            for(int i=0; i<16; i++) { // 행(y)
                String rowInput = sc.nextLine();
                for(int j=0; j<16; j++) { // 열(x)
                    // j => x , i => y
                    map[i][j] = rowInput.charAt(j) - '0';
                    visited[i][j] = 0;
                    if(map[i][j] == 2) {
                        startY = i;
                        startX = j;
                    }
                }
            }
             
            findPath = false;
            findView(startY, startX);
             
            System.out.println(String.format("#%d %d", T, findPath ? 1:0));
        }
         
    }
     
    public static void findView(int y, int x) {
        // 1, -1이 겹치지 않게 방향설정 (왼쪽, 아랫쪽, 오른쪽, 위쪽)
        int[] rotX = {-1,0,1,0};
        int[] rotY = {0,1,0,-1};
         
        // 도킹
        visited[y][x] = 1;
        int newX, newY;
        for(int i=0; i<4; i++) {
            // 왼쪽, 아랫쪽, 오른쪽, 위쪽을 우선순위로 탐색
            newX = x + rotX[i];
            newY = y + rotY[i];
            if(isWay(newY, newX)) { // 길이 있는 경우면 전진
                 
                // 도중에 출구를 발견한 경우
                if(map[newY][newX]==3) {
                    findPath = true;
                    break;
                }
                 
                findView(newY, newX); // 무한 재귀호출
            }
        }
        // 도킹 해제
        visited[y][x] = 0;
    }
     
    public static boolean isWay(int y, int x) {
        if(x<0 || x>15 || y<0 || y>15) { // 배열 범위를 넘어서는 경우
            return false;
        }else if(visited[y][x]==1){ // 지나온 곳은 통과할 수 없다.
            return false;
        }else if(map[y][x]==1) { // 벽은 통과할 수 없다.
            return false;
        }else if(findPath) {
            // 이미 길을 찾은 경우 break point 재귀함수를 모두 종류하기 위하여
            return false;
        }
        return true;
    }
     
}


import java.util.Scanner;
 
 
class Solution {
    static int Answer;
 
    public static void main(String args[]) throws Exception {
         
         
        Scanner sc = new Scanner(System.in);
         
        for(int T=1; T <=10; T++) {
             
            // dump 횟수
            int dumpCount = sc.nextInt();
            sc.nextLine();
             
            // 숫자 리스트
            String[] strNumList = sc.nextLine().trim().split(" ");
            int[] countArr = new int[101]; // 0 ~ 100
             
            // 각각의 숫자들을 카운팅
            int min=101, max=0;
            for(String strNum : strNumList) {
                int height = Integer.parseInt(strNum);
                countArr[height]++;
            }
             
             
            for(int j=0; j<=dumpCount; j++) {
                // 최대값 스캔
                for(int k=100; k>=0; k--) {
                    if(countArr[k] != 0) {
                        max = k;
                        break;
                    }
                }
                 
                // 최소값 스캔
                for(int k=0; k<=100; k++) {
                    if(countArr[k] != 0) {
                        min = k;
                        break;
                    }
                }
                 
                if(j!=dumpCount) {
                    // 블록옴기기 ( 0 ~ dumpCount-1 까지)
                    countArr[max]--;
                    countArr[max-1]++;
                    countArr[min]--;
                    countArr[min+1]++;
                }
            }
             
             
            // 높이차 출력
            System.out.println(String.format("#%d %d", T, max-min) );
             
        }
         
    }
}


import java.util.Scanner;
 
 
class Solution {
    static int Answer;
 
    public static void main(String args[]) throws Exception {
         
         
        Scanner sc = new Scanner(System.in);
         
        for(int T=1; T <=10; T++) {
            int size = sc.nextInt();
            int[] inputList = new int[size];
            for(int i=0; i <size ;i++) {
                inputList[i] = sc.nextInt();
            }
             
            // i 번째 조망권 (양옆 2이 배열범위에 벗어나지 않았을 떄 가정)
            int viewCount = 0;
            for(int i=0; i<size ; i++) {
                int left_2 = i-2 >= 0 ? inputList[i-2] : 0;
                int left_1 = i-1 >= 0 ? inputList[i-1] : 0;
                int right_1 = i + 1 < size ? inputList[i+1] : 0;
                int right_2 = i + 2 < size ? inputList[i+2] : 0;
                 
                int max = left_2;
                if(max < left_1) {max = left_1;}
                if(max < right_1) {max = right_1;}
                if(max < right_2) {max = right_2;}
                 
                viewCount += inputList[i] > max ? inputList[i]-max : 0;
            }
             
            System.out.println(String.format("#%d %d", T, viewCount) );
        }
         
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;


public class Main {
	
	public static void main(String[] args) {
		
		InputStream in = System.in;
		Reader isr = new InputStreamReader(in);
		BufferedReader br = new BufferedReader(isr);
		
		String[] input;
		int whatNumber = 0;
		int minlength = 0;
		try {
			input = br.readLine().split(" ");
			whatNumber = Integer.parseInt(input[0]);
			minlength = Integer.parseInt(input[1]);
		} catch (IOException e) {
			// e.printStackTrace();
		} 
		
		for(int i=minlength ; i <=100 ; i++) {
			
			if(getSolution(i, whatNumber)) {
				// log("getSolution(%d, %d)", i, whatNumber);
				printAnswear(i, whatNumber);
				break;
			}
			if(i==100) {
				log("-1");
			}
		}
		
	}

	// n : n 개의 연속 되는 수
	public static boolean getSolution(int n, int result) {
		// n = 1 일 때      k (단, k는 자연수 ) 
		// n = 2 일 때     2k + 1
		// n = n 일 때  nk + n(n-1)/2
		
		// result = nk + n(n-1)/2
		// result - n(n-1)/2 = nk
		// [result - n(n-1)/2] % n == 0 이라면 k정수가 존재
		
		int x = result - n*(n-1)/2;
		if(x < 0) {
			return false;
		}
		
		boolean okay = (x % n == 0) ;
		
		return okay;
	}

	public static void printAnswear(int n, int result) {
		int first = (result - n*(n-1)/2) / n;
		
		String Str = "";
		for(int i=0; i<n; i++) {
			Str += String.format("%d ", first+i);
		}
		System.out.println(Str.trim());
	}
	
	public static void log(String input) {	System.out.println(input);	}

	public static void log(String input, Object ...args) {
		System.out.println(String.format(input, args));
	}
	
}


+ Recent posts