자료구조와 알고리즘/문제풀기

완전탐색 - 백준(10250) ACM 호텔

now0204 2024. 4. 16. 13:14

 

- 풀이

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());

        while (n-- > 0){
            String[] input = br.readLine().split(" ");
            int h = Integer.parseInt(input[0]);
            int w = Integer.parseInt(input[1]);
            int cus = Integer.parseInt(input[2]);



            //나중에 조정해보자  층수는 무조건 맞는데 호수가 문제임 ! 일단 완탐으로 바꾸자
            // 층 수는 높이로 나눈 나머지, 호수는 높이로 나눈 몫
            // 문제는 나머지나 몫이 0~h-1이 아니라 1~h구간으로 표시되어야함 
            // 이와 같이 구간 변경할 때는 ((h-1)/h +1 해줌) 
            int ch = (cus-1)%h +1;
            int wh = (cus-1)/h +1;
            String result = ch+"";
            result+= wh > 9 ? wh+"" : "0"+wh;
            bw.write(result+"\n");

        }

        bw.flush();
        bw.close();
    }

    
}

 

 

- 얻은 점

 

  > 나머지 연산과 나누기 연산 구간 변경시  

  > [0,h-1] -> [1,h] => (target - 1) (%,/) d +1

 

 

https://www.acmicpc.net/problem/10250

 

10250번: ACM 호텔

프로그램은 표준 입력에서 입력 데이터를 받는다. 프로그램의 입력은 T 개의 테스트 데이터로 이루어져 있는데 T 는 입력의 맨 첫 줄에 주어진다. 각 테스트 데이터는 한 행으로서 H, W, N, 세 정수

www.acmicpc.net