当前位置: 首页 > 工具软件 > Murder > 使用案例 >

ZOJ_3317_Murder in Restaurant

冯庆
2023-12-01
ZOJ Problem Set - 3317
Murder in Restaurant
Time Limit: 1 Second      Memory Limit: 32768 KB

Murder in closet happened again in a small restaurant and Conan went there to collect evidence with Kogoro. After they reached the restaurant, they got a list of renters that lived in this restaurant recently. Yet the list was so long that they couldn't get the useful information from it. As an assistant of Conan, you must have been ready to help him to get the information on which rooms the renters have lived in.

Input

There are no more than 20 test cases. The first line of each test case contains two integers n and m, indicating the number of renters and the rooms of the restaurant (0 < n, m <= 100). The i-th line of the next n lines contains two integers t1 and t2, the day when they wanted to check in and to leave (0 < t1 < t2 <= 1000).

Each renter rends exactly one room and their check-in days are distinct. Each time a renter came, the owner would give him/her an available room with minimum room number if there were still empty rooms. Otherwise the renter would leave at once and never come back again. Note that rooms are always returned in morning and rented in afternoon. The input is ended with two zeroes.

Output

For each test case, output n lines of integers. The i-th integer indicates the room number of the i-th renter. The rooms are numbered from 1. If someone didn't live in this restaurant, output 0 in the corresponding line.

Sample Input

 

2 5
1 3
2 4
4 2
1 5
2 3
3 5
4 5
0 0

 

Sample Output

 

1
2
1
2
2
0

 


Author: GUAN, Yao
Source: The 10th Zhejiang University Programming Contest
Submit    Status #include<iostream>
using namespace std;typedef struct Person{
 int id;
 int roomNum;
 int t1, t2;
}Persons;int getRoomNum( Persons* people, int i, int n );int main(void)
{
 int n, m;
 Persons people[100];
 cin>>n>>m;
 while(n!=0||m!=0){
  for( int i = 0; i < n; i++ ){
   people[i].id = i;
   cin>>people[i].t1>>people[i].t2;
  }
  Persons temp;
  for( int i = 0; i < n; i++ ){
   for( int j = 0; j < n-1-i; j++ )
    if( people[j].t1 > people[j+1].t1 ){
     temp = people[j];
     people[j] = people[j+1];
     people[j+1] = temp;
    }
  }
  for( int i = 0; i < n; i++ )
   people[i].roomNum = getRoomNum( people, i, m );
  for( int i = 0; i < n; i++ ){
   for( int j = 0; j < n-1-i; j++ )
    if( people[j].id > people[j+1].id ){
     temp = people[j];
     people[j] = people[j+1];
     people[j+1] = temp;
    }
  }
  for( int i = 0; i < n; i++ )
   cout<<(people[i].roomNum+1)<<endl;
  cin>>n>>m;
 }
 return 0;
}int getRoomNum( Persons* people, int i, int n )
{
 int count = 0;
 for( int j = 0; j < n; j++ )
  for( int k = 0; k < i; k++ ){
   if( j == people[k].roomNum && people[i].t1 >= people[k].t1 && people[i].t1 < people[k].t2 ){
    if( count == people[k].roomNum )
        count++;
    break;
   }
  }
 if( count == n )
  return -1;
 else
  return count;
}
 类似资料:

相关阅读

相关文章

相关问答