ZOJ Problem Set - 3317 Murder in Restaurant

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 integersn andm, indicating the number of renters and the rooms of the restaurant (0 <n,m <= 100).Thei-th line of the next n lines contains two integerst1 andt2, 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 thei-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
注意一次性输出所有人的住房信息!!!!
源代码
#include<stdio.h>
#include<algorithm>
#include <deque>
using namespace std;
struct data{
    int s;
    int e;
    int id;
    int room;
}renter[101];//记入每位客人的信息
int mark[101];//记入每个房间入住客人的离开时间
int cmp1(data a,data b){
    if(a.s<b.s)
        return 1;
    else 
        return 0;
}
int cmp2(data a,data b){
    if(a.id<b.id)
        return 1;
    else
        return 0;
}
int main(){
    int i,j,n,m;
    while(scanf("%d%d",&n,&m),n+m){
        for(i=1;i<=m;i++){
            mark[i]=0;
        }
        for(i=0;i<n;i++){
            scanf("%d%d",&renter[i].s,&renter[i].e);
            renter[i].id=i;
        }
        sort(renter,renter+n,cmp1);
        for(i=0;i<n;i++){
            for(j=1;j<=m;j++){
                if(mark[j]<=renter[i].s){
                    mark[j]=renter[i].e;
                    renter[i].room=j;
                    break;
                }
                    
            }
            if(j>m)
                renter[i].room=0;
        }
        sort(renter,renter+n,cmp2);
        for(i=0;i<n;i++){
            printf("%d/n",renter[i].room);
        }
    }
    return 0;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值