HDU - 4122 Alice's mooncake shop 单调队列

 

题字:给你n份订单m小时制作yuebing

          n行订单的时间(月日年小时)和需要月饼的数量r

         每个月饼的保质期为t放冰箱每小时需要s的代价

         给出0-m-1每小时制作月饼的代价

         求完成所有月饼所需的代价

思路:将订单的时间先换算成小时

           根据米个小时的不同加葛

           第i个小时的月饼订单是(it,i)这个区间的做月饼最小的代价min(费用【i】,费用【k】+(ik)* s)

           所以我们要维护i区间前的最小值=维护一个单调递增的队列

          ACcode:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int Date[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
struct node{
    int num,time;
}order[maxn];
int dpmax[maxn];//维护一个单调递增的队列
int cost[maxn];
int Month(char month[]){
    if(strcmp(month,"Jan") == 0)  return 1;
    if(strcmp(month,"Feb") == 0)  return 2;
    if(strcmp(month,"Mar") == 0)  return 3;
    if(strcmp(month,"Apr") == 0)  return 4;
    if(strcmp(month,"May") == 0)  return 5;
    if(strcmp(month,"Jun") == 0)  return 6;
    if(strcmp(month,"Jul") == 0)  return 7;
    if(strcmp(month,"Aug") == 0)  return 8;
    if(strcmp(month,"Sep") == 0)  return 9;
    if(strcmp(month,"Oct") == 0)  return 10;
    if(strcmp(month,"Nov") == 0)  return 11;
    if(strcmp(month,"Dec") == 0)  return 12;
} 
inline int Flag(int year){ //闰年
    return (year%4 == 0 && year%100 != 0)|| year % 400 == 0;
}
inline int Time(int year ,int month,int day,int hour){
    int res=0;
    for(int i=2000;i<year;i++){
        if(Flag(i)) res+=366;
        else        res+=365;
    }
    int flag=Flag(year);
    for(int i=1;i<month;i++){
        if(flag && i== 2) res+=29;
        else              res+=Date[i];
    }
    res+=day-1;
    return res*24+hour;
}
int n,m;
int main(){
    while(scanf("%d%d",&n,&m)!=EOF){
        if(n == 0 && m == 0) break;
        for(int i=1;i<=n;i++){
            char month[10];int day,year,hour;int num;
            scanf("%s%d%d%d%d",month,&day,&year,&hour,&num);
            order[i].num=num;order[i].time=Time(year,Month(month),day,hour);//转化成小时
        }
        int t,s;scanf("%d%d",&t,&s);
        int maxtop=1,maxend=1,now=1;
        long long  ans=0;// 这里需要64位维护  32位会爆
        for(int i=0;i<m;i++){
            scanf("%d",&cost[i]);
            while(maxtop < maxend && (i-dpmax[maxend-1])*s+cost[dpmax[maxend-1]] >= cost[i] ) maxend--;  //假如队尾的代价 大于 当前代价 出队
            dpmax[maxend++]=i;
            while(now <= n && i == order[now].time){
                while(t+dpmax[maxtop] < i )  maxtop++; //保证最小的代价是在保质期内
                ans+=order[now].num*(cost[ dpmax[maxtop] ] + (i-dpmax[maxtop])*s);
                now++;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值