hdu+1103

qq_46297150 2020-09-15 09:27:07
hdu+1103 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 <iostream> using namespace std; int main(){ int a,b,c; while(cin>>a>>b>>c&&a!=0&&b!=0&&c!=0){ char t[6]; int d=0,j[a],k[b],l[c],t1[a],t2[b],t3[c],x=a,y=b,z=c,i=0; for(i=0;i<a;i++) j[i]=0; for(i=0;i<b;i++) k[i]=0; for(i=0;i<c;i++) l[i]=0; for(i=0;i<a;i++) t1[i]=1; for(i=0;i<b;i++) t2[i]=1; for(i=0;i<c;i++) t3[i]=1; while(cin>>t&&t[0]!='#'){ int n,m,s,q; cin>>n; m=(t[0]-'0')*10+t[1]-'0'; s=(t[3]-'0')*10+t[4]-'0'; q=m*60+s; if(n<=2){ for(i=0;i<a;i++){ if(j[i]+30<=q&&j[i]!=0){ x++; t1[i]=1; }} if(x>=1){ x--; for(i=0;i<a;i++){ if(t1[i]==1){ j[i]=q; t1[i]=0; d+=n; break;}}} else{ for(i=0;i<a;i++){ if(j[i]<=q){ j[i]+=30; d+=n; break;}}}} else if(n>2&&n<=4){ for(i=0;i<a;i++){ if(k[i]+30<=q&&k[i]!=0){ y++; t2[i]=1;}} if(y>=1){ y--; for(i=0;i<a;i++){ if(t2[i]==1){ k[i]=q; t2[i]=0; break;}} d+=n; } else{ for(i=0;i<a;i++){ if(k[i]<=q){ k[i]+=30; d+=n; break;}}}} else{ for(i=0;i<a;i++){ if(l[i]+30<=q&&l[i]!=0){ z++; t3[i]=1;}} if(z>=1){ z--; for(i=0;i<a;i++){ if(t3[i]==1){ l[i]=q; t3[i]=0; break;}} d+=n; } else{ for(i=0;i<a;i++){ if(l[i]<=q){ l[i]+=30; d+=n; break;}}}} } cout<<d<<endl; } return 0; } 求大佬查错,主要是餐馆没有空桌时要等30分钟的情况也加上去了
...全文
32 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧