本文主要是介绍习题5-16 医院设备利用(Use of Hospital Facilities,ACM/ICPC World Finals 1991,UVa212),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接:https://vjudge.net/problem/UVA-212
分类:<algorithm>
备注:中级模拟,输出格式
前言:输出格式懒得数的直接看下面代码,很清楚了,注意每组数据最后还要输出空行。这UVA的PDF让我们通过数dash来数空格我能理解,但是空行是多少肉眼看不出来啊,居然两个表之间只有一个空行,还不说明清楚,正式比赛也会这样吗?还有第二个表开头并不要一个空格,PDF显示的不一样啊,要是没uDebug和之前做过的人的经验真不知道怎么办。
还有,容我再吐槽一句,为什么刘老师您不是完全按照难度给题目排序呢,明明前面还有更难的。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 10 + 5;
const int maxm = 30 + 5;
const int maxp = 100 + 5;
int n, m, st, t1, t2, t3, k, alltime;
int op[maxn], use1[maxn], re[maxm], use2[maxm];
struct patient {char name[10];int ot, rt;int room, begin1, end1;int bed, begin2, end2;int id;
}p[maxp];
bool cmp1(const patient& p1, const patient& p2) {if (p1.end1 != p2.end1)return p1.end1 < p2.end1;return p1.room < p2.room;
}
bool cmp2(const patient& p1, const patient& p2) {return p1.id < p2.id;
}
void simulate() {for (int i = 0; i < k; i++) {int minop = 0;for (int j = 1; j < n; j++)if (op[j] < op[minop])minop = j;//找最早的开放时间p[i].room = minop + 1;p[i].begin1 = op[minop];p[i].end1 = op[minop] + p[i].ot;use1[minop] += p[i].ot;op[minop] = p[i].end1 + t2;//更新开放时间}sort(p, p + k, cmp1);int last = 0;for (int i = 0; i < k; i++) {for (int j = 0; j < m; j++) {if (re[j] <= p[i].end1) {p[i].bed = j + 1;p[i].begin2 = p[i].end1 + t1;p[i].end2 = p[i].begin2 + p[i].rt;use2[j] += p[i].rt;re[j] = p[i].end2 + t3;last = max(last, p[i].end2);break;}}}sort(p, p + k, cmp2);alltime = last - st;
}
int main(void) {int flag = 0;while (~scanf("%d %d %d %d %d %d %d", &n, &m, &st, &t1, &t2, &t3, &k)) {getchar();st = st * 60;for (int i = 0; i < n; i++)op[i] = st;for (int i = 0; i < m; i++)re[i] = st;memset(use1, 0, sizeof(use1));memset(use2, 0, sizeof(use2));for (int i = 0; i < k; i++) {scanf("%s", p[i].name);scanf("%d%d", &p[i].ot, &p[i].rt);getchar();p[i].id = i + 1;}puts(" Patient Operating Room Recovery Room");puts(" # Name Room# Begin End Bed# Begin End");puts(" ------------------------------------------------------");simulate();for (int i = 0; i < k; i++) {int hour1 = p[i].begin1 / 60, minute1 = p[i].begin1 % 60; int hour2 = p[i].end1 / 60, minute2 = p[i].end1 % 60;int hour3 = p[i].begin2 / 60, minute3 = p[i].begin2 % 60;int hour4 = p[i].end2 / 60, minute4 = p[i].end2 % 60;printf("%2d %-10s", p[i].id, p[i].name);printf("%2d %2d:%02d %2d:%02d ", p[i].room, hour1, minute1, hour2, minute2);printf(" %2d %2d:%02d %2d:%02d\n", p[i].bed, hour3, minute3, hour4, minute4);}printf("\n");puts("Facility Utilization");puts("Type # Minutes % Used");puts("-------------------------");for (int i = 0; i < n; i++)printf("Room %2d %4d %5.2lf\n", i + 1, use1[i], 100.0 * use1[i] / alltime);for (int i = 0; i < m; i++)printf("Bed %2d %4d %5.2lf\n", i + 1, use2[i], 100.0 * use2[i] / alltime);putchar('\n');}return 0;
}
这篇关于习题5-16 医院设备利用(Use of Hospital Facilities,ACM/ICPC World Finals 1991,UVa212)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!