HDU 4122

Alice‘s mooncake shop

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3340    Accepted Submission(s): 843

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.

Input

The input contains no more than 10 test cases. 
For each test case:
The first line includes two integers N and M. N is the total number of orders. M is the number of hours the shop opens. 
The next N lines describe all the orders. Each line is in the following format:

month date year H R

It means that on a certain date, a customer orders R mooncakes at H o’clock. “month” is in the format of abbreviation, so it could be "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" or "Dec". H and R are all integers. 
All the orders are sorted by the time in increasing order. 
The next line contains T and S meaning that the storage life of a mooncake is T hours and the cost to store a mooncake for an hour is S.
Finally, M lines follow. Among those M lines, the ith line( i starts from 1) contains a integer indicating the cost to make a mooncake during the ith hour . The cost is no more than 10000. Jan 1st 2000 0 o‘clock belongs to the 1st hour, Jan 1st 2000 1 o‘clock belongs to the 2nd hour, …… and so on.

(0<N <= 2500; 0 < M,T <=100000; 0<=S <= 200; R<=10000 ; 0<=H<24)

The input ends with N = 0 and M = 0.

Output

You should output one line for each test case: the minimum cost.

Sample Input

1 10
Jan 1 2000 9 10
5 2
20
20
20
10
10
8
7
9
5
10
0 0

Sample Output

70

Hint

“Jan 1 2000 9 10” means in Jan 1st 2000 at 9 o‘clock , there‘s a consumer ordering 10 mooncakes.
Maybe you should use 64-bit signed integers. The answer will fit into a 64-bit signed integer.

Source

2011 Asia Fuzhou Regional Contest

Recommend

lcy

开始没读懂题意,后来闰年天数弄错了,再后来二月天数弄错了,最后没有清零,最终A的时候我也是醉了。。。

单调队列

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%I64d", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%I64d\n", n)
#define MAXN 1000005

string mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
ll py[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll ny[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll ppy[13];
ll nny[13];
ll dy[MAXN];
map<string, ll> mh;
struct P{
  ll hh, rr;
  P(ll _h = 0, ll _w = 0) : hh(_h), rr(_w) {}
  bool operator < (const P& t) const
  {
      return hh > t.hh;
  }
}order[2505];
struct W{
  ll t, w;
  W(ll _t = 0, ll _w = 0) : t(_t), w(_w) {}
};
queue<P> O;
deque<W> T;
void get_np()
{
    ppy[0] = 0;
    repu(i, 1, 13) ppy[i] = py[i - 1] + ppy[i - 1];
    nny[0] = 0;
    repu(i, 1, 13) nny[i] = ny[i - 1] + nny[i - 1];
}

void get_m()
{
    for(int i = 0; i < 12; i++)
        mh[mon[i]] = i + 1;
}

bool is_y(int year)
{
    if(year % 400 == 0) return true;
    if(year % 4 == 0)
    {
        if(year % 100 == 0) return false;
        else return true;
    }
    return false;
}

void get_d()
{
    dy[0] = 0;
    for(int i = 2000; ; i++)
    {
        if(is_y(i)) dy[i - 2000 + 1] = dy[i - 2000] + 366;
        else dy[i - 2000 + 1] = dy[i - 2000] + 365;
        if(dy[i - 2000 + 1] > 10000) return ;
        //cout<<i - 2000 + 1<<" : "<<dy[i - 2000 + 1]<<endl;
    }
}

int main()
{
    get_d();
    get_m();
    get_np();
    ll n, m;
    string s;
    ll mm, yy, dd, hh, rr, tt;
    ll life, cost;
    while(sfl(n), sfl(m), n + m)
    {
        T.clear();
        repu(i, 0, n)
        {
            tt = 0;
            cin>>s;
            scanf("%I64d %I64d %I64d %I64d", &dd, &yy, &hh, &rr);
            mm = mh[s];
            tt += dy[yy - 2000];
            if(is_y(yy))
                tt += ppy[mm - 1];
            else tt += nny[mm - 1];
            tt += (dd - 1);
            tt = tt * (ll)(24);
            tt += (hh + 1);
            O.push(P(tt, rr));
            //cout<<tt<<"**************"<<rr<<endl;
        }
        sfl(life), sfl(cost);
        ll x;
        ll sum = 0;
        repu(i, 1, m + 1)
        {
            sfl(x);
            while(!T.empty() && x <= T.back().w + (i - T.back().t) * cost)
                T.pop_back();
            T.push_back(W(i, x));
            while(!O.empty() && O.front().hh == i)
            {
                while(!T.empty() && (i - T.front().t) > life)
                    T.pop_front();
                sum += O.front().rr * (T.front().w + cost * (i - T.front().t));
                O.pop();
            }
        }
        pfl(sum);
    }
    return 0;
}

时间: 2024-09-30 14:19:11

HDU 4122的相关文章

hdu 4122 Alice&#39;s mooncake shop

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意大意是Alice开着一家月饼店,可以接到n做月饼的订单,而Alice只有在从2000年一月一日0点为第一个小时开始的前m个小时内做月饼,而且只能在整点 的时候做月饼,并且做月饼不花费时间,也就是一瞬间就可以做超级多的月饼,而每个月饼有t个小时的保质期,每个月饼保存每小时需要花费s元,而在可以 做月饼的m小时内,不同小时做月饼花费的钱也不同,每个订单都有交付订单嗯达时间,某年某月某日某时交付该

HDU 4122 Alice&#39;s mooncake shop 单调队列优化dp

Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4122 Description The Mid-Autumn Festival, also known as the Moon Festival or Zhongqiu Festival is a popular harvest festival celebrated by Ch

HDU 4122 Alice&#39;s mooncake shop --RMQ

题意: 一个月饼店做月饼,总营业时间m小时,只能在整点做月饼,可以做无限个,不过在不同的时间做月饼的话每个月饼的花费是不一样的,假设即为cost[i],再给n个订单,即为在某个时间要多少个月饼,时间从2000年1月1日0时开始计算,必须在每个订单的时间之前完成这么多月饼,月饼还有保质期T小时以及保存费用S每小时,现在问满足这n个点的最小成本是多少. 解法: 因为月饼有保质期T,所以第i个月饼只能在[Ti-T+1,Ti]时间内做好.如果时间j有订单,假设在时间i做月饼是最好的,那么这个订单每个月饼

hdu 4122 Alice&amp;#39;s mooncake shop (线段树)

题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ) 整理一下会发现式子就是 cost[]-j*s + i*s 对于每个订单,我们把i拿出来分析 所以也就用cost - j*s 建树. 然后在储存期间找到最小的花费即可了. #include <cstdio> #include <iostream> #include <algo

【单调队列】HDU 4122 Alice&#39;s mooncake shop

通道:http://acm.hdu.edu.cn/showproblem.php?pid=4122 题意:给定N和M,表示有N个订单,M个时刻可以做月饼,时刻以小时计算,任意时刻可以做若干个月饼.接着N行为N个订单的信息,包括时间和数量.再给定T和S,表示每个月饼的保质时间和每保存一小时的开销.然后M行为对应每个时刻制作月饼的代价.问说最少花费多少代价完成所有订单 思路:维护单调队列,把之前的花费大于当前的pop掉,把不满足保鲜期内的pop掉 代码:https://github.com/Mith

hdu 4122 Alice&#39;s mooncake shop (线段树)

题目大意: 一个月饼店每个小时做出月饼的花费不一样. 储存起来要钱,最多存多久.问你把所有订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ) 整理一下会发现式子就是 cost[]-j*s + i*s 对于每一个订单,我们把i拿出来分析 所以也就用cost - j*s 建树. 然后在储存期间找到最小的花费就行了. #include <cstdio> #include <iostream> #include <algo

hdu 4122 Alice&#39;s mooncake shop(单调队列)

题目链接:hdu 4122 Alice's mooncake shop 题目大意:给定N和M,表示有N个订单,M个时刻可以做月饼,时刻以小时计算,任意时刻可以做若干个月饼.接着 N行为N个订单的信息,包括时间和数量.再给定T和S,表示每个月饼的保质时间和每保存一小时的开销.然后M行为 对应每个时刻制作月饼的代价.问说最少花费多少代价完成所有订单. 解题思路:单调队列或者RMQ,单调队列即用一个deque维护一个代价递增的队列,每次将头部保质期不够的剔除. RMQ可以将预处理处每个区间时刻代价的最

HDU 4122 单调队列

转载自:http://blog.csdn.net/lvshubao1314/article/details/46910271 DES :给出n个订单和m是商店的开放时间.然后n行给出n个订单的信息.然后给出t和s.表示一个月饼的保质期和保存一天的成本.最后m行,给出每个时刻做月饼的成本.问.完成订单的最少的成本是多少. 思路就是用单调队列保存每个点之前的可以为这个点做月饼的点.刚学了单调队列.在保存下标然后找到值哪里还是有一些混乱. 第一次错了.闰年是366天.搞混了.T_T.不过时间方面的计算

滑动窗口的单调队列

今天的训练赛HDU 4122,卡到最后也没出来,结束后和队友冷静分析代码后才发现错在一个简单的错误上,修改后A了 赛后看题解,大家的题解中大都提到了要用单调队列. 去网上搜单调队列..文章无外乎就两种..= =  抄袭好严重呀 1.http://zhonghuan.info/2014/09/16/%E6%B5%85%E6%9E%90%E5%8D%95%E8%B0%83%E9%98%9F%E5%88%97/ 简单的单调队列 2.http://blog.pureisle.net/archives/4