博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1103 Flo's Restaurant(模拟+优先队列)
阅读量:4696 次
发布时间:2019-06-09

本文共 3673 字,大约阅读时间需要 12 分钟。

Flo's Restaurant

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1519    Accepted Submission(s): 465


Problem Description
Sick and tired of pushing paper in the dreary bleary-eyed world of finance, Flo ditched her desk job and built her own restaurant.
In the small restaurant, there are several two-seat tables, four-seat tables and six-seat tables. A single diner or a group of two diners should be arranged to a two-seat table, a group of three or four diners should be arranged to a four-seat table, and a group of five or six diners should be arranged to a six-seat table.
Flo’s restaurant serves delicious food, and many people like to eat here. Every day when lunch time comes, the restaurant is usually full of diners. If there is no suitable table for a new coming group of diners, they have to wait until some suitable table is free and there isn’t an earlier arrival group waiting for the same kind of tables. Kind Flo will tell them how long they will get their seat, and if it’s longer than half an hour, they will leave for another restaurant.
Now given the list of coming diners in a day, please calculate how many diners take their food in Flo’s restaurant. You may assume it takes half an hour for every diner from taking a seat to leaving the restaurant.
 

Input
There are several test cases. The first line of each case contains there positive integers separated by blanks, A, B and C (A, B, C >0, A + B + C <= 100), which are the number of two-seat tables, the number of four-seat tables and the number of six-seat tables respectively. From the second line, there is a list of coming groups of diners, each line of which contains two integers, T and N (0 < N <= 6), representing the arrival time and the number of diners of each group. The arrival time T is denoted by HH:MM, and fixed between 08:00 and 22:00 (the restaurant closes at 23:00). The list is sorted by the arrival time of each group in an ascending order, and you may assume that no groups arrive at the same time. Each test case is ended by a line of “#”.
A test case with A = B = C = 0 ends the input, and should not be processed.
 

Output
For each test case, you should output an integer, the total number of diners who take their food in Flo’s restaurant, in a separated line.
 

Sample Input
 
1 1 1 10:40 1 10:50 2 11:00 4 # 1 1 1 10:40 1 10:50 2 11:00 2 # 1 2 1 10:30 1 10:40 3 10:50 2 11:00 1 11:20 5 # 0 0 0
 

Sample Output
 
7 3

12

直接模拟,一开始我用一个优先队列表示所有的餐桌,后来发现行不通的,只能用三个优先队列表示三个餐桌,然后就是简单模拟

#include 
#include
#include
#include
#include
#include
#include
using namespace std;int A,B,C;int a[10];struct Node{ int time;//吃完饭的时间 int pos;//几号桌 int p;//几个人 friend bool operator<(Node n1,Node n2) { return n1.time>n2.time; } Node(){}; Node(int time,int pos,int p){this->time=time;this->pos=pos;this->p=p;}}d;priority_queue
q[10];char e[105];int num;int main(){ while(scanf("%d%d%d",&a[2],&a[4],&a[6])!=EOF) { if(a[2]==0&&a[4]==0&&a[6]==0) break; int cot=0; for(int i=2;i<=6;i+=2) { while(!q[i].empty()) q[i].pop(); for(int j=1;j<=a[i];j++) q[i].push(Node(0,i,0)); } int ans=0; while(scanf("%s",e)) { if(e[0]=='#') break; scanf("%d",&num); d.time=((e[0]-'0')*10+e[1]-'0')*60+(e[3]-'0')*10+e[4]-'0'; d.p=num; d.pos=(num&1?num+1:num); Node term=q[d.pos].top(); if(d.time>=term.time) {d.time+=30;ans+=d.p;q[d.pos].pop();q[d.pos].push(d);} else if(d.time+30>=term.time) {d.time=term.time+30;ans+=d.p;q[d.pos].pop();q[d.pos].push(d);} } printf("%d\n",ans); } return 0;}

转载于:https://www.cnblogs.com/dacc123/p/8228749.html

你可能感兴趣的文章
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
postgressql数据库中limit offset使用
查看>>
测试思想-集成测试 关于接口测试 Part 2
查看>>
php生成器使用总结
查看>>