Murder in Restaurant
来源:互联网 发布:硬盘初始化 数据错误 编辑:程序博客网 时间:2024/05/21 11:20
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.
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.
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.
2 51 32 44 21 52 33 54 50 0
121220
题目大意:
第一行给出两个数字n,m
n代表房客个数m代表房间数
主人给房客安排房间从1开始到m
下面n行代表n个房客的需求 入住时间和不住的时间
我们需要输出每一个房客的入住的房间号
如果没有房间住就输出0
代码
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>#include<ctype.h>#include<stack>#include<queue>using namespace std;struct nana{ int i,o,r,n;}a[10003];int cmp1(nana a,nana b){ if(a.i==b.i) return a.o<b.o; return a.i<b.i;}int cmp2(nana a,nana b){ return a.n<b.n;}int main(){ int n,m; int r[1003]; while(scanf("%d%d",&n,&m)==2&&n) { for(int i=0;i<1003;i++)r[i]=0; for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].i,&a[i].o); a[i].n=i; } sort(a+1,a+n+1,cmp1); for(int i=1;i<=n;i++) { int flag=0; for(int j=1;j<=m;j++) { if(a[i].i>=r[j]) { a[i].r=j; r[j]=a[i].o; flag=1; break; } } if(!flag) a[i].r=0; } sort(a+1,a+n+1,cmp2); for(int i=1;i<=n;i++) { printf("%d\n",a[i].r); } }}
- Murder in Restaurant
- Murder in Restaurant
- ZOJ 3317 Murder in Restaurant
- zoj 3317 Murder in Restaurant
- ZOJ Problem Set - 3317 Murder in Restaurant
- zoj3317——Murder in Restaurant
- ZOJ 3317 Murder in Restaurant模拟(解题报告)
- ZOJ 3317 Murder in Restaurant(数学啊 )
- ZOJ_3317_Murder in Restaurant
- zoj3317Murder in Restaurant
- In Chinese Restaurant
- Ural 1962 In Chinese Restaurant
- Restaurant
- Restaurant
- Restaurant
- A Japanese guy in China restaurant.
- URAL1962:In Chinese Restaurant(并查集)
- URAL 1962 In Chinese Restaurant 并查集
- Spark系统运行内幕机制循环流程
- keil中文乱码解决和个人习惯字体设置
- 大数据下基于Tensorflow框架的深度学习示例教程
- 动态内存管理
- 上周热点回顾(1.30-2.5)
- Murder in Restaurant
- vbs修改系统时间,增加或减少任意秒数
- iOS 10推送
- 【技巧】CSS 居中的三种方法
- host XXX is not allowed to connect to this MariaDB
- ES6利用Number.isNaN()更合理的判断NAN
- I/O流的梳理和小结
- 《跟我一起写makefile》(笔记3--命令书写)
- Android 入门教程:安装 Android Studio