Use of Hospital Facilities

Use of Hospital Facilities


来源:UVA - 212


题目描述:

County General Hospital is trying to chart its course through the troubled waters of the economy and
shifting population demographics. To support the planning requirements of the hospital, you have been
asked to develop a simulation program that will allow the hospital to evaluate alternative configurations
of operating rooms, recovery rooms and operations guidelines. Your program will monitor the usage of
operating rooms and recovery room beds during the course of one day.
County General Hospital has several operating rooms and recovery room beds. Each surgery patient
is assigned to an available operating room and following surgery the patient is assigned to one of the
recovery room beds. The amount of time necessary to transport a patient from an operating room to
a recovery room is fixed and independent of the patient. Similarly, both the amount of time to prepare
an operating room for the next patient and the amount of time to prepare a recovery room bed for a
new patient are fixed.
All patients are officially scheduled for surgery at the same time, but the order in which they actually
go into the operating rooms depends on the order of the patient roster. A patient entering surgery goes
into the lowest numbered operating room available. For example, if rooms 2 and 4 become available
simultaneously, the next patient on the roster not yet in surgery goes into room 2 and the next after
that goes into room 4 at the same time. After surgery, a patient is taken to the available recovery room
bed with the lowest number. If two patients emerge from surgery at the same time, the patient with
the lower number will be the first assigned to a recovery room bed. (If in addition the two patients
entered surgery at the same time, the one first on the roster is first assigned a bed.)


输入格式:

The input file contains data for a single simulation run. All numeric data in the input file are integers,
and successive integers on the same line are separated by blanks. The first line of the file is the set of
hospital configuration parameters to be used for this run. The parameters are, in order:
Number of operating rooms (maximum of 10)
Number of recovery room beds (maximum of 30)
Starting hour for 1st surgery of day (based on a 24-hour clock)
Minutes to transport patient from operating room to recovery room
Minutes to prepare operating room for next patient
Minutes to prepare recovery room bed for next patient
Number of surgery patients for the day (maximum of 100)
This initial configuration data will be followed by pairs of lines of patient data as follows:
Line 1: Last name of patient (maximum of 8 characters)
Line 2: Minutes required for surgery Minutes required in the recovery room
Patient records in the input file are ordered according to the patient roster, which determines the
order in which patients are scheduled for surgery. The number of recovery room beds specified in any
configuration will be sufficient to handle patients arriving from surgery (No queuing of patients for
recovery room beds will be required). Computed times will not extend past 24:00.


输出格式:

Correct output shows which operating room and which recovery room bed is used by each patient, and
the time period that the patient uses the room and bed along with a summary of the utilization of
hospital facilities for that day. The output file consists of a set of two tables describing the results of
the simulation run. The first table is in columnar form with appropriate column labels to show the
number of each patient (in the order the patient roster), the patient’s last name, the operating room
number, the time surgery beings and ends, the recovery bed number and the time the patient enters
and leaves the recovery room bed.
The second table will also be in columnar form with appropriate column labels summarizing the
utilization of operating rooms and recovery room beds. This summary indicates the facility type (room
or bed), the facility number, the number of minutes used and percentage of available time utilized.
Available time is defined as the time in minutes from the starting time for 1-st surgery of day to the
ending time of the last patient in a recovery room bed.


输入样例:

5 12 07 5 15 10 16
Jones
28 140
Smith
120 200
Thompson
23 75
Albright
19 82
Poucher
133 209
Comer
74 101
Perry
93 188
Page
111 223
Roggio
69 122
Brigham
42 79
Nute
22 71
Young
38 140
Bush
26 121
Cates
120 248
Johnson
86 181
White
92 140
5 12 07 5 15 10 16
Jones
28 140
Smith
120 200
Thompson
23 75
Albright
19 82
Poucher
133 209
Comer
74 101
Perry
93 188
Page
111 223
Roggio
69 122
Brigham
42 79
Nute
22 71
Young
38 140
Bush
26 121
Cates
120 248
Johnson
86 181
White
92 140

输出样例:

 Patient          Operating Room          Recovery Room
 #  Name     Room#  Begin   End      Bed#  Begin    End
 ------------------------------------------------------
 1  Jones      1    7:00    7:28      3    7:33    9:53
 2  Smith      2    7:00    9:00      1    9:05   12:25
 3  Thompson   3    7:00    7:23      2    7:28    8:43
 4  Albright   4    7:00    7:19      1    7:24    8:46
 5  Poucher    5    7:00    9:13      5    9:18   12:47
 6  Comer      4    7:34    8:48      4    8:53   10:34
 7  Perry      3    7:38    9:11      2    9:16   12:24
 8  Page       1    7:43    9:34      6    9:39   13:22
 9  Roggio     4    9:03   10:12      9   10:17   12:19
10  Brigham    2    9:15    9:57      8   10:02   11:21
11  Nute       3    9:26    9:48      7    9:53   11:04
12  Young      5    9:28   10:06      3   10:11   12:31
13  Bush       1    9:49   10:15     10   10:20   12:21
14  Cates      3   10:03   12:03      8   12:08   16:16
15  Johnson    2   10:12   11:38      4   11:43   14:44
16  White      5   10:21   11:53      7   11:58   14:18

Facility Utilization
Type  # Minutes  % Used
-------------------------
Room  1     165   29.68
Room  2     248   44.60
Room  3     258   46.40
Room  4     162   29.14
Room  5     263   47.30
Bed   1     282   50.72
Bed   2     263   47.30
Bed   3     280   50.36
Bed   4     282   50.72
Bed   5     209   37.59
Bed   6     223   40.11
Bed   7     211   37.95
Bed   8     327   58.81
Bed   9     122   21.94
Bed  10     121   21.76
Bed  11       0    0.00
Bed  12       0    0.00

 Patient          Operating Room          Recovery Room
 #  Name     Room#  Begin   End      Bed#  Begin    End
 ------------------------------------------------------
 1  Jones      1    7:00    7:28      3    7:33    9:53
 2  Smith      2    7:00    9:00      1    9:05   12:25
 3  Thompson   3    7:00    7:23      2    7:28    8:43
 4  Albright   4    7:00    7:19      1    7:24    8:46
 5  Poucher    5    7:00    9:13      5    9:18   12:47
 6  Comer      4    7:34    8:48      4    8:53   10:34
 7  Perry      3    7:38    9:11      2    9:16   12:24
 8  Page       1    7:43    9:34      6    9:39   13:22
 9  Roggio     4    9:03   10:12      9   10:17   12:19
10  Brigham    2    9:15    9:57      8   10:02   11:21
11  Nute       3    9:26    9:48      7    9:53   11:04
12  Young      5    9:28   10:06      3   10:11   12:31
13  Bush       1    9:49   10:15     10   10:20   12:21
14  Cates      3   10:03   12:03      8   12:08   16:16
15  Johnson    2   10:12   11:38      4   11:43   14:44
16  White      5   10:21   11:53      7   11:58   14:18

Facility Utilization
Type  # Minutes  % Used
-------------------------
Room  1     165   29.68
Room  2     248   44.60
Room  3     258   46.40
Room  4     162   29.14
Room  5     263   47.30
Bed   1     282   50.72
Bed   2     263   47.30
Bed   3     280   50.36
Bed   4     282   50.72
Bed   5     209   37.59
Bed   6     223   40.11
Bed   7     211   37.95
Bed   8     327   58.81
Bed   9     122   21.94
Bed  10     121   21.76
Bed  11       0    0.00
Bed  12       0    0.00



思路:

首先构建病人、手术室和恢复室三个结构体,用于存储病人、手术室和恢复室的信息。
总时间:最后一个离开恢复室的病人的离开时刻减去第一个开始手术的病人的开始手术时刻。
手术室:使用时间即所有在此手术室进行手术的病人的手术时间之和;使用率即使用时间除以总时间。
恢复室:使用时间即所有在此恢复室进行恢复的病人的恢复时间之和;使用率即使用时间除以总时间。

模拟

  • 排队进行手术:对于每个病人,找出最早开放的手术室,病人进入此手术室进行手术,更改病人和手术室的相关信息。当所有病人均手术完之后,需要对病人排序,排序标准:按病人手术结束时间进行升序排序,若有不止一位病人在某一时刻结束手术,按病人进行手术的手术室编号进行升序排序。
  • 排队进行恢复:对于每个病人,按恢复室编号由小到大遍历每个恢复室,一旦这个恢复室的开放时间小于等于病人的手术结束时间,则立即把病人由手术室送往恢复室,并修改病人和恢复室的相关信息。在每一个病人恢复期间,求出最后一个离开恢复室的病人的恢复结束时间,用此时间减去手术室开放时间即可得到总时间。当所有病人均恢复完之后,对病人按病人编号进行升序排序(因输出时需要按病人编号升序输出病人信息)。

AC代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void __init__ ()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // ios::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
}

struct Patient
{
    int id;
    char name[10];
    int op_time, re_time;
    int room;
    int op_begin, op_end;
    int bed;
    int re_begin, re_end;
};

bool cmp1 (const Patient& p1, const Patient& p2)
{
    if (p1.op_end != p2.op_end) return p1.op_end < p2.op_end;
    return p1.room < p2.room;
}

bool cmp2 (const Patient& p1, const Patient& p2)
{
    return p1.id < p2.id;
}

struct OperatingRoom
{
    int open_time;
    int use_time;
};

struct RecoveryRoom
{
    int open_time;
    int use_time;
};

vector<OperatingRoom> op;
vector<RecoveryRoom> re;
vector<Patient> p;
int n, m, T, t1, t2, t3, k, all_time; 

void init ()
{
    T *= 60;
    for (int i = 0; i < n; i++)
    {
        op[i].open_time = T;
        op[i].use_time = 0;
    }
    for (int i = 0; i < m; i++)
    {
        re[i].open_time = T;
        re[i].use_time = 0;
    }
}

void simulate ()
{
    for (int i = 0; i < k; i++)
    {
        int min_op = 0;
        for (int j = 1; j < n; j++) 
            if (op[j].open_time < op[min_op].open_time) 
                min_op = j;
        p[i].room = min_op + 1;
        p[i].op_begin = op[min_op].open_time;
        p[i].op_end = p[i].op_begin + p[i].op_time;
        op[min_op].open_time = p[i].op_end + t2;
        op[min_op].use_time += p[i].op_time; 
    }
    sort(p.begin(), p.end(), cmp1);
    int last = 0;
    for (int i = 0; i < k; i++)
        for (int j = 0; j < m; j++)
            if (re[j].open_time <= p[i].op_end)
            {
                p[i].bed = j + 1;
                p[i].re_begin = p[i].op_end + t1;
                p[i].re_end = p[i].re_begin + p[i].re_time;
                re[j].open_time = p[i].re_end + t3;
                re[j].use_time += p[i].re_time;
                last = max(last, p[i].re_end);
                break;
            }
    all_time = last - T;
    sort(p.begin(), p.end(), cmp2);
}

void print ()
{
	puts(" Patient          Operating Room          Recovery Room");
	puts(" #  Name     Room#  Begin   End      Bed#  Begin    End");
	puts(" ------------------------------------------------------");
    for (int i = 0; i < k; i++)
    {
        int op_begin_hour = p[i].op_begin / 60, op_begin_minute = p[i].op_begin % 60;
        int op_end_hour = p[i].op_end / 60, op_end_minute = p[i].op_end % 60;
        int re_begin_hour = p[i].re_begin / 60, re_begin_minute = p[i].re_begin % 60;
        int re_end_hour = p[i].re_end / 60, re_end_minute = p[i].re_end % 60;
		printf("%2d  %-10s", p[i].id, p[i].name);
		printf("%2d   %2d:%02d   %2d:%02d    ", p[i].room, op_begin_hour, op_begin_minute, op_end_hour, op_end_minute);
		printf(" %2d   %2d:%02d   %2d:%02d\n", p[i].bed, re_begin_hour, re_begin_minute, re_end_hour, re_end_minute);
    }
    puts("");
    puts("Facility Utilization");
	puts("Type  # Minutes  % Used");
	puts("-------------------------");   
    for (int i = 0; i < n; i++)
        printf("Room %2d    %4d   %5.2lf\n", i + 1, op[i].use_time, 100.0 * op[i].use_time / all_time);
    for (int i = 0; i < m; i++)
        printf("Bed  %2d    %4d   %5.2lf\n", i + 1, re[i].use_time, 100.0 * re[i].use_time / all_time);
    puts("");
}

int main ()
{
    __init__();

    while(~scanf("%d %d %d %d %d %d %d", &n, &m, &T, &t1, &t2, &t3, &k))
    {
        getchar();
        op.resize(n);
        re.resize(m);
        p.resize(k);
        for (int i = 0; i < k; i++) 
        {
            scanf("%s %d %d", p[i].name, &p[i].op_time, &p[i].re_time);
            p[i].id = i + 1;
        }
        init();
        simulate();
        print();
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值