单调队列1002 HDU 4122 Alice's mooncake shop 对于学习单调队列的同学不建议做,浪费时间的模拟水题

来源:互联网 发布:cf有刷枪软件吗 编辑:程序博客网 时间:2024/04/30 21:17

Problem Description

The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Chinese people, dating back over 3,000 years to moon worship in China’s Shang Dynasty. The Zhongqiu Festival is held on the 15th day of the eighth month in the Chinese calendar, which is in September or early October in the Gregorian calendar. It is a date that parallels the autumnal equinox of the solar calendar, when the moon is at its fullest and roundest.

The traditional food of this festival is the mooncake. Chinese family members and friends will gather to admire the bright mid-autumn harvest moon, and eat mooncakes under the moon together. In Chinese, “round”(圆) also means something like “faultless” or “reuion”, so the roundest moon, and the round mooncakes make the Zhongqiu Festival a day of family reunion.

Alice has opened up a 24-hour mooncake shop. She always gets a lot of orders. Only when the time is K o’clock sharp( K = 0,1,2 …. 23) she can make mooncakes, and We assume that making cakes takes no time. Due to the fluctuation of the price of the ingredients, the cost of a mooncake varies from hour to hour. She can make mooncakes when the order comes,or she can make mooncakes earlier than needed and store them in a fridge. The cost to store a mooncake for an hour is S and the storage life of a mooncake is T hours. She now asks you for help to work out a plan to minimize the cost to fulfill the orders.

题意:
一个人开一个月饼店,给出n个顾客来取月饼的时间和数量
店主只在整点的时候做月饼,可以做无限个月饼,并时间为0
每个月饼的保质期是T小时,每小时保鲜需要S
每个小时原材料的价格是波动的,给出每个小时的价格
求出最少花费满足所有顾客
思路:
对于学习单调队列的同学不建议做…感觉是浪费时间的题…
就是一些麻烦的处理,然后维护一个当前没过期并且花费最小的月饼
RMQ,线段树,单调队列还有什么区间查询的数据结构都可以解决
还有一个比较坑的地方是可能存在两个顾客的时间一样
所以一定一定要用while QAQ

#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>#include<queue>#include<stack>#include<string>#include<vector>#include<map>#include<set>using namespace std;#define lowbit(x) (x&(-x))typedef long long LL;const int maxn = 100005;const int inf=(1<<28)-1;int GetMonth(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;}bool LeapYear(int Year){    if(Year%4==0&&Year%100!=0||Year%400==0) return 1;    return 0;}int OverMonth(int year,int month){    if(month==1) return 31;    if(month==2)     {        if(LeapYear(year))        return 29;        return 28;    }    if(month==3) return 31;    if(month==4) return 30;    if(month==5) return 31;    if(month==6) return 30;    if(month==7) return 31;    if(month==8) return 31;    if(month==9) return 30;    if(month==10) return 31;    if(month==11) return 30;    if(month==12) return 31;}int n,m;int GetHour(int Year,int Month,int Date,int Hour){    int Time=0;    for(int i=2000;i<Year;++i)    if(LeapYear(i)) Time+=366*24;    else Time+=365*24;    for(int i=1;i<Month;++i)    Time+=OverMonth(Year,i)*24;    for(int i=1;i<Date;++i)    Time+=24;    Time+=Hour;    //printf("%d\n",Time);    return Time;}deque<int>Que;LL A[maxn];LL Need[5005],NeedNum[5005];int main(){    while(~scanf("%d%d",&n,&m)&&!(n==0&&m==0))    {        char Month[5];        int MaxTime=0;        for(int i=0;i<n;++i)        {            int date,year,Hour,month;            LL Num;            scanf("%s%d%d%d%lld",Month,&date,&year,&Hour,&Num);            month=GetMonth(Month);            Hour=GetHour(year,month,date,Hour);            Need[i]=Hour;            NeedNum[i]=Num;            MaxTime=max(MaxTime,Hour);            //printf("%d\n",Hour);        }        Que.clear();        int time,Cost;        scanf("%d%d",&time,&Cost);        for(int i=0;i<m;++i)        {            scanf("%lld",&A[i]);        }        LL MinCost=0;        int NowCustomer=0;        for(int i=0;i<m;++i)        {            while(!Que.empty()&&A[Que.back()]+(i-Que.back())*Cost>=A[i])            Que.pop_back();            Que.push_back(i);            while(!Que.empty()&&i-Que.front()>time)            Que.pop_front();            while(i==Need[NowCustomer])            {                MinCost+=(A[Que.front()]+(i-Que.front())*Cost)*NeedNum[NowCustomer];                NowCustomer++;            }        }        printf("%lld\n",MinCost);    }    return 0;}
0 0
原创粉丝点击