首页 > 代码库 > 【模拟】Flo's Restaurant
【模拟】Flo's Restaurant
[poj2424]Flo‘s Restaurant
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2960 | Accepted: 929 |
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.
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.
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 110:40 110:50 211:00 4#1 1 110:40 110:50 211:00 2#1 2 110:30 110:40 310:50 211:00 111:20 5#0 0 0
Sample Output
7312
Source
PKU Monthly,Alcyone
试题分析:简单模拟一下现在每个桌子最先走的就好了……
代码
#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<algorithm> using namespace std;inline int read(){ int x=0,f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1; for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘; return x*f; }int A,B,C;int le1[101],le2[101],le3[101];int HH,MM,P;int k[4];char s[7];int main(){ k[1]=read(),k[2]=read(),k[3]=read(); while(k[1]!=0||k[2]!=0||k[3]!=0){ int res=0; memset(le1,0,sizeof(le1)); memset(le2,0,sizeof(le2)); memset(le3,0,sizeof(le3)); while(1){ cin>>s; if(s[0]==‘#‘) break; HH=0; int tmp=1,e=1; for(tmp=0;s[tmp]!=‘:‘;tmp++) ; for(int i=tmp-1;i>=0;i--) HH+=((s[i]-‘0‘)*e),e*=10; MM=0,e=1; for(int i=strlen(s)-1;i>tmp;i--) MM+=((s[i]-‘0‘)*e),e*=10; int T=(HH-7)*60+MM; //cout<<T<<endl; P=read(); P++; if(P/2==1&&k[1]){ P--; sort(le1,le1+k[1]); if(le1[0]-T<=30){ // cout<<"true"<<endl; res+=P; if(le1[0]>=T) le1[0]+=30; else le1[0]=T+30; } } else if(P/2==2&&k[2]){ P--; sort(le2,le2+k[2]); if(le2[0]-T<=30){ //cout<<"true2"<<endl; res+=P; if(le2[0]>=T) le2[0]+=30; else le2[0]=T+30; } } else if(P/2==3&&k[3]){ P--; sort(le3,le3+k[3]); if(le3[0]-T<=30){ //cout<<"true3"<<endl; res+=P; if(le3[0]>=T) le3[0]+=30; else le3[0]=T+30; } } } printf("%d\n",res); k[1]=read(),k[2]=read(),k[3]=read(); }}/*1 3 209:45 309:46 509:59 410:00 110:01 310:20 310:30 211:20 511:40 112:00 312:10 214:20 515:00 315:20 615:40 517:30 219:00 619:40 420:03 420:05 421:40 221:44 122:00 1#*/
【模拟】Flo's Restaurant
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。