• HDU1103


    题意:一家店从早上8点开始营业,一共有3种座位(2人座,4人座,6人座),每次来一批客人 吃饭时间30分钟,下一批没座的客人最多等30分钟

    模拟!

    关键在于存储每种座位什么时候是空的,或者说什么时候客人会离开,可以用队列来存储!(题目给定的就是按时间顺序的)

    View Code
      1 #include<stdio.h>
      2 #include<algorithm>
      3 #include<stdlib.h>
      4 #include<queue>
      5 using namespace std;
      6 const int maxn = 1005;
      7 struct node{
      8     int t,num;
      9 }a[ maxn ];
     10 queue<int>q1;
     11 queue<int>q2;
     12 queue<int>q3;
     13 //1 2 3分别存储着2人座,4人座,6人座的人的离开时间
     14 int main(){
     15     int A,B,C;
     16     while( scanf("%d%d%d",&A,&B,&C)==3 ,A+B+C ){
     17         int cnt=0;
     18         while( !q1.empty() )q1.pop();
     19         while( !q2.empty() )q2.pop();
     20         while( !q3.empty() )q3.pop();
     21         char s[ 10 ];
     22         while( scanf("%s",s)!=EOF ){
     23             if( strcmp( s,"#" )==0 )
     24                 break;
     25             int time=0,num;
     26             time=( s[4]-'0' )+( s[3]-'0' )*10+60*( (s[1]-'0')+10*(s[0]-'0') );
     27             scanf("%d",&num);
     28             a[ cnt ].num=num,a[ cnt ].t=time,cnt++;
     29         }//input
     30         int ans=0;
     31         int time1,time2,time3;
     32         for( int i=0;i<cnt;i++ ){
     33             /*
     34             if( a[i].t>last_time )
     35                 break;
     36             if( time1>last_time+30||time2>last_time+30||time3>last_time+30 )
     37                 break;
     38                 */
     39             if( a[i].num>=1&&a[i].num<=2 ){
     40                 if( A>0 ) {
     41                     A--;
     42                     ans+=a[i].num;
     43                     q1.push( (a[i].t+30) );
     44                 }//如果有空位
     45                 else {
     46                     time1=q1.front();
     47                     if( a[i].t>=time1-30&&a[i].t<=time1 ){
     48                         ans+=a[i].num;
     49                         q1.pop();
     50                         q1.push( max(a[i].t+30,time1+30) );
     51                     }//等上一波客人30分钟
     52                     else if( a[i].t>time1 ) {
     53                         q1.pop();
     54                         ans+=a[i].num;
     55                         q1.push( a[i].t+30 );
     56                     }//有空位
     57                 }
     58             }//2
     59             else if( a[i].num>=3&&a[i].num<=4 ){
     60                 if( B>0 ) {
     61                     B--;
     62                     ans+=a[i].num;
     63                     q2.push( (a[i].t+30) );//the every end time
     64                 }
     65                 else {
     66                     time2=q2.front();
     67                     if( a[i].t>=time2-30&&a[i].t<=time2 ){
     68                         ans+=a[i].num;
     69                         q2.pop();
     70                         q2.push( max(a[i].t+30,time2+30) );
     71                     }//等上一波客人30分钟
     72                     else if( a[i].t>time2 ) {
     73                         q2.pop();
     74                         ans+=a[i].num;
     75                         q2.push( a[i].t+30 );
     76                     }
     77                 }
     78             }//4
     79             else if( a[i].num>=5&&a[i].num<=6 ){
     80                 if( C>0 ) {
     81                     C--;
     82                     ans+=a[i].num;
     83                     q3.push( (a[i].t+30) );//the every end time
     84                 }
     85                 else {
     86                     time3=q3.front();
     87                     if( a[i].t>=time3-30&&a[i].t<=time3 ){
     88                         ans+=a[i].num;
     89                         q3.pop();
     90                         q3.push( max(a[i].t+30,time3+30) );
     91                     }//等上一波客人30分钟
     92                     else if( a[i].t>time3 ) {
     93                         q3.pop();
     94                         ans+=a[i].num;
     95                         q3.push( a[i].t+30 );
     96                     }
     97                 }
     98             }//6
     99         }
    100         printf("%d\n",ans);
    101     }
    102     return 0;
    103 }
    keep moving...
  • 相关阅读:
    优秀开源项目
    详细解读Android中的搜索框(四)—— Searchable配置文件
    详细解读Android中的搜索框(三)—— SearchView
    详细解读Android中的搜索框(二)—— Search Dialog
    判断listview滑动方向的代码片段
    详细解读Android中的搜索框(一)—— 简单小例子
    通过Spannable对象设置textview的样式
    用开源项目circular progress button实现有进度条的Button
    低版本系统兼容的ActionBar(七)自定义Actionbar标题栏字体
    WebView入门
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2908122.html
Copyright © 2020-2023  润新知