题目大意:

一个月饼店每一个小时做出月饼的花费不一样。

储存起来要钱。最多存多久。问你把全部订单做完的最少花费。

思路分析:

ans = segma( num[]*(cost[] + (i-j)*s) )

整理一下会发现式子就是

cost[]-j*s + i*s

对于每个订单,我们把i拿出来分析

所以也就用cost - j*s 建树。

然后在储存期间找到最小的花费即可了。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#define lson num<<1,s,mid
#define rson num<<1|1,mid+1,e
#define maxn 2555
#define maxm 100005
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n,m;
int days[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}};
string tab[] = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
LL tre[maxm<<2]; int getmonth(string x)
{
for(int i=1;i<=12;i++)
if(x==tab[i])return i;
}
bool leap(int x)
{
if(((x%4==0) && x%100!=0) || x%400==0)return true;
return false;
}
LL gethour(int month,int day,int year,int hour)
{
LL res=day-1;
int is=leap(year);
for(int i=1;i<month;i++)res+=days[is][i];
for(int i=2000;i<year;i++)
res+=365+leap(i);
res*=24;
res+=hour+1;
return res;
}
void build(int num,int s,int e)
{
tre[num]=inf;
if(s==e)return;
int mid=(s+e)>>1;
build(lson);
build(rson);
}
void update(int num,int s,int e,int pos,LL val)
{
if(s==e)
{
tre[num]=val;
return;
}
int mid=(s+e)>>1;
if(pos<=mid)update(lson,pos,val);
else update(rson,pos,val);
tre[num]=min(tre[num<<1],tre[num<<1|1]);
}
LL query(int num,int s,int e,int l,int r)
{
if(l<=s && r>=e)
{
return tre[num];
}
int mid=(s+e)>>1;
if(r<=mid)return query(lson,l,r);
else if(l>mid)return query(rson,l,r);
else return min(query(lson,l,mid),query(rson,mid+1,r));
} string tmp;
LL num[maxn];
LL cost[maxm];
LL time[maxm];
int main()
{
while(cin>>n>>m)
{
if(n==0 && m==0)break;
for(int i=1;i<=n;i++)
{
int d,y,h,Num;
cin>>tmp;
cin>>d>>y>>h>>Num;
num[i]=Num;
time[i]=gethour(getmonth(tmp),d,y,h);
}
LL S,T;
build(1,1,m);
cin>>T>>S;
for(int i=1;i<=m;i++)
{
cin>>cost[i];
cost[i]-=i*S;
update(1,1,m,i,cost[i]);
}
LL ans=0;
for(int i=1;i<=n;i++)
{
if(time[i]>m)break;
ans+=num[i]*(query(1,1,m,max(1LL,time[i]-T+1),time[i])+time[i]*S);
}
cout<<ans<<endl;
}
return 0;
}

hdu 4122 Alice&#39;s mooncake shop (线段树)的更多相关文章

  1. 【hdu】Mayor&#39;s posters(线段树区间问题)

    须要离散化处理,线段树的区间改动问题. 须要注意的就是离散化的时候,由于给的数字是一段单位长度,所以须要特殊处理(由于线段的覆盖和点的覆盖是不一样的) 比方:(1,10)(1,4) (6,10) 离散 ...

  2. hdu 4122 Alice's mooncake shop(单调队列)

    题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...

  3. HDU 4122 Alice's mooncake shop 单调队列优化dp

    Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  4. HDU 4122 Alice's mooncake shop (RMQ)

    Alice's mooncake shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. hdu acm 1166 敌兵布阵 (线段树)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  6. HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...

  7. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  8. HDU 3974 Assign the task (DFS序 + 线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 给你T组数据,n个节点,n-1对关系,右边的是左边的父节点,所有的值初始化为-1,然后给你q个操 ...

  9. hdu 3333 Turing Tree 图灵树(线段树 + 二分离散)

    http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Others)    ...

随机推荐

  1. HTML JS 数据校验

    用到了html字符串校验,这里记录一下. <html> <head> <script type="text/javascript"> funct ...

  2. C# MemCached分布式缓存

    using System; using System.Collections.Generic; using System.Text; using Memcached.ClientLibrary; us ...

  3. git pull fails “unable to resolve reference” “unable to update local ref”

    问题 由于有人rebase了分支,或者不知道怎么搞的.其他人拉取代码的时候,发现拉不下来. >git fetch error: cannot lock ref 'refs/remotes/ori ...

  4. 如何配置官方peerDroid,使其运行起来

    一.Peer Droid是JXME协议到android平台的移植,开发者可以利用它来实现android设备以及传统PC机通讯的应用程序,peerDroid的官方demo主要是实现PC端peer和and ...

  5. Introduction to Learning to Trade with Reinforcement Learning

    http://www.wildml.com/2015/12/implementing-a-cnn-for-text-classification-in-tensorflow/ The academic ...

  6. Concurrent HTTP connections in Node.js

    原文: https://fullstack-developer.academy/concurrent-http-connections-in-node-js/ -------------------- ...

  7. Pandas DataFrame笔记

    1.属性方式,可以用于列,不能用于行 2.可以用整数切片选择行,但不能用单个整数索引(当索引不是整数时) 3.直接索引可以使用列.列集合,但不能用索引名索引行 用iloc取行,得到的series: d ...

  8. 在Excel中输入超过10的带圈数字

    通过改变字体,可以在excel中输入1-20的带圈数字.对于某些人这些还不够用,那怎么办呢? 有了下面这个不知道是哪个大神做的字体,你就可以直接输到100啦 将字体文件文件粘贴至“C:\WINDOWS ...

  9. [Algorithm] Binary tree: Level Order Traversal

    function Node(val) { return { val, left: null, right: null }; } function Tree() { return { root: nul ...

  10. Masonry应用【美图秀秀首页界面自动布局】

    Masonry在此实现时候,并没有比NSLayoutConstraint简单,相反我觉得还不如NSLayoutConstraint. [self.topView mas_makeConstraints ...