HDU ACM 1103 Flo's Restaurant

来源:互联网 发布:天津伊势丹mac是正品吗 编辑:程序博客网 时间:2024/05/12 00:29

分析:借助STL的min_element实现。每次更新最先被占用的桌子,具体见注释。

#include<iostream>#include<algorithm>using namespace std;int main(){int A,B,C;char s[10];int a[102],b[102],c[102];int curtime,count,ans;int *p;              //桌子最先空闲时间while(cin>>A>>B>>C,A+B+C){memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));ans=0;while(cin>>s && s[0]!='#'){curtime=(s[0]-'0')*10+(s[1]-'0');curtime=curtime*60+(s[3]-'0')*10+(s[4]-'0');cin>>count;if(count==1||count==2){p=min_element(a,a+A);  //取得最小值(也即桌子的最早空余时间)if(*p<=curtime+30)            //顾客等30分钟后是否有座位{if(*p<=curtime) *p=curtime+30;  //最先被占用的桌子的顾客已经离开了,新顾客可以入座else *p+=30;        //新顾客还需等待ans+=count;}}if(count==3||count==4){p=min_element(b,b+B);  //取得最小值(也即桌子的最早空余时间)if(*p<=curtime+30)            //顾客等30分钟后是否有座位{if(*p<=curtime) *p=curtime+30;  //最先被占用的桌子的顾客已经离开了,新顾客可以入座else *p+=30;        //新顾客还需等待ans+=count;}}if(count==5||count==6){p=min_element(c,c+C);  //取得最小值(也即桌子的最早空余时间)if(*p<=curtime+30)            //顾客等30分钟后是否有座位{if(*p<=curtime) *p=curtime+30;  //最先被占用的桌子的顾客已经离开了,新顾客可以入座else *p+=30;        //新顾客还需等待ans+=count;}}}cout<<ans<<endl;}return 0;}


0 0
原创粉丝点击