银行排队模拟
来源:互联网 发布:淘宝卖家批量发货 编辑:程序博客网 时间:2024/04/30 04:32
Baggage Room
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
Schoolboys Vasya and Pete travel a lot. They use baggage rooms really often. Baggage room has M windows, numbered 1 through M. When a lot of people come, there are big queues in front of windows. Newly come person stands in the queue with the least number of people. If there are several such queues than he or she chooses queue to the window with lowest number. When the queue is chosen, the decision will not further change. When next person comes to the window, he or she spends some time near the window to take or get his stuff, pay money, etc. (let's call it servicing time). This time is specific to each person and doesn't depend on the window. During this time the person is counted as standing in the queue. If new person come in the moment when one or several peoplehave just proceeded to their windows, he or she waits first until these people will leave their queues and then he or she chooses the queue to stand in. Vasya and Pet e wonder when each particular person will leave the queue. Please help them.
Input
The first line of the input file contains two integer numbers N, M (1 ≤ N ≤ 100; 1 ≤ M ≤ 100), where N - number of people, M - number of windows in the baggage room. Next N lines contain pairs of integer numbers ki, ti (1 ≤ ki ≤ 1000; 1 ≤ ti ≤ 100), where ki - time moment, when ith person came, ti - servicing time of ith person. Persons are listed in order of increase of ki.
Output
Print N lines. Print in the ith line two numbers - number of the queue, that would be chosen by ith person and moment of the time, when he or she will leave the queue.
Sample Input
sample input
sample output
5 21 23 44 15 26 1
1 31 72 52 71 8
#include <iostream>#include <string.h>#include <cmath>#include <algorithm>using namespace std;#define MAXN 100 + 10int num[MAXN];int wait_time[MAXN];int current_time, last_time;int person[10 * MAXN];int time[10 * MAXN];bool vis[10 * MAXN];void input(){ int n, m; while (cin >> n >> m) { memset(num, 0, sizeof(num)); memset(wait_time, 0, sizeof(wait_time)); memset(person, 0, sizeof(person)); memset(vis, false, sizeof(vis)); for (int i = 0; i < n; i++) { cin >> current_time >> last_time; for (int j = 0; j < i; j++) { if (time[j] <= current_time && !vis[j]) { vis[j] = true; num[person[j]]--; } } int *p = min_element(num, num + m); person[i] = p - num; num[p - num]++; wait_time[p - num] = wait_time[p - num] > current_time ? wait_time[p - num] + last_time : current_time + last_time; time[i] = wait_time[p - num]; cout << p - num + 1 << ' ' << time[i] << endl; } }}int main(){ input(); return 0;}
0 0
- 银行排队模拟
- 银行排队模拟
- 模拟银行排队系统
- 离散事件模拟--银行排队时间模拟
- 模拟银行排队叫号机 2011.04.18
- 转载:C++ 实现银行排队服务模拟
- C++ 实现银行排队服务模拟
- 银行排队系统模拟—数据结构
- 银行排队叫号系统的模拟
- 银行排队
- 银行排队
- 模拟银行窗口排队叫号系统的运作
- c++版模拟银行窗口排队叫号系统
- 基于uc银行排队叫号模拟系统(winxp)
- 1014. Waiting in Line (30) 模拟银行排队
- Java -- 队列(模拟银行的排队办理业务)
- 严蔚敏 数据结构C语言 银行排队队列 离散事件模拟
- 黑马程序员——根据银行排队取号系统模拟餐馆排队取号
- IEEE地址和网络地址
- 翻转字符串的解法
- Ubuntu 网络配置
- android Activity的Task Affinity lanchMode
- Android视频录制命令screenrecord
- 银行排队模拟
- ORA-01455报错的问题探究
- python文件读写操作
- 外企面试注意事项
- 设置窗体的起始位置,并检查配置文件是否存在,存在使用配置文件,不存在创建配置文件,在每次打开窗体时保持窗体上一次关闭的位置。
- 一个外企资深工程师的对编程的感悟
- ios侧拉菜单
- 如何开待软件实施人员
- 美元汇率波动 苹果AppStore应用要涨价了