Contents

[백준 10250]ACM 호텔 - JAVA 풀이

   Aug 20, 2021     1 min read     - Comments

바로가기

문제

문제


해석

  1. 호텔 전 객실이 빈방이다.

  2. 방은 먼저온 손님 순으로 층이 낮고 엘리베이터가 가까운 곳으로 배정해준다.

  3. 이 때, N번째 손님에게 배정될 방 호수를 구하는 문제


풀이

  1. n % h를 하면 몇 층에 배정될 지를 알 수 있다. 예외적으로 나머지가 0이 나오면 h값을 반환 한다.
    n % h == 0 ? h : n % h
    
  2. (n-1) / h + 1 을 하면 그 층의 몇번 째 방인지를 알 수 있다.

  3. 1번 * 100 + 2번을 하면 방의 호수를 알 수 있다.

코드

import java.util.*;
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 t = Integer.parseInt(br.readLine());
        
        for(int i = 0 ; i < t; i++)
            bw.write(calc(br.readLine()) + "\n");
        
        bw.flush();
        bw.close();
    }
    
    public static int calc(String s){
        StringTokenizer st = new StringTokenizer(s);
        
        int h = Integer.parseInt(st.nextToken());
        int w = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
      
        return  (n % h == 0 ? h : n % h) * 100 + ((n-1) / h  + 1);
    }
}