[Problem]
Jiwoo, the manager of the ACM Hotel, is about to assign the vacant rooms to the guests upon their arrival. According to customers’ survey, the customers prefer the rooms which are close to the main entrance on-walk. Jiwoo likes to assign the rooms on this policy. Write a program to help Jiwoo on assigning the rooms for the guests.
For simplicity, let’s assume that the ACM hotel is a rectangular shape, an H story building with W rooms on each floor (1 ≤ H, W ≤ 99) and that the only one elevator is on the leftmost side (see Figure 1). Let’s call this kind of hotel as H × W shaped. The main entrance is located on the first floor near the elevator. You may ignore the distance between the gate and the elevator. Also assume that the distances between neighboring rooms are all the same, the unit distance, and that all the rooms only in the front side of the hotel.
The rooms are numbered in YXX or YYXX style where Y or YY denotes the number of the floor and XX, the index of the room counted from the left. Therefore the room shaded in Figure 1 should be 305.
The customers do not concern the distance moved in the elevator though the room on the lower floor is preferred than that on the higher floor if the walking distance is same. For instance, the room 301 is preferred than the room 102 since the customer should walk for two units for the latter but one unit, for the former. Additionally, the room 2101 is preferred than the room 102.
Your program should compute the room number which should be assigned for the N-th guest according to this policy assuming that all the rooms are vacant initially. The first guest should be assigned to 101, the second guest to 201, and so on. In Figure 1, for example, the 10th guest should be assigned to the room 402 since H = 6.
[input]
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case consists of a single line containing and integers H, W, and N: the number of floors, the number of rooms on each floor, and the index of the arrival time of the guest to be assigned a room, respectively, where 1 ≤ H, W ≤ 99 and 1 ≤ N ≤ H × W.
[output]
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case consists of a single line containing and integers H, W, and N: the number of floors, the number of rooms on each floor, and the index of the arrival time of the guest to be assigned a room, respectively, where 1 ≤ H, W ≤ 99 and 1 ≤ N ≤ H × W.
[solution]
#include <stdio.h>int main(){
int tc; //variable definition : test_case
scanf("%d",&tc);
while(tc>0){
int h,w,n; // h = height, w = width, n = the number of customers
scanf("%d %d %d",&h,&w,&n);
int room[h][w]; // array size = height * width ( the number of rooms)
int i,j;
for(i=1;i<=w;i++){
for(j=1;j<=h;j++){
room[j-1][i-1]=(100*j)+i; // ex) A room number = height * 100 + width ----> No.301 = 3 * 100 + 1 ** Insert a room number in turns into the array
}
}
if(n%h==0) printf("%d\n",room[h-1][n/h-1]);
else printf("%d\n",room[(n%h)-1][n/h]);
// If the number of customers and height are same, (height 6, customers 6) or
if the number of customers is multiple of height, customers will be enter in the top room.
The room number is one less than the index. --> room[h-1][n/h-1]
Except in the case of above, the row has the height of hotel. the column has room nuber.
In other words, you can make this expression. room[(n%h)-1][n/h]
tc--;
}
return 0;
}
problem reference : https://www.acmicpc.net/problem/10250
Thank you for reading.
I never stop programming. Because I'm a beginner. :)
댓글 없음:
댓글 쓰기