hdu 4122 Alice's mooncake shop (线段树)
题目大意:
一个月饼店每一个小时做出月饼的花费不一样。
储存起来要钱。最多存多久。问你把全部订单做完的最少花费。
思路分析:
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's mooncake shop (线段树)的更多相关文章
- 【hdu】Mayor's posters(线段树区间问题)
须要离散化处理,线段树的区间改动问题. 须要注意的就是离散化的时候,由于给的数字是一段单位长度,所以须要特殊处理(由于线段的覆盖和点的覆盖是不一样的) 比方:(1,10)(1,4) (6,10) 离散 ...
- hdu 4122 Alice's mooncake shop(单调队列)
题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...
- 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 ...
- 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 ...
- hdu acm 1166 敌兵布阵 (线段树)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 4911 http://acm.hdu.edu.cn/showproblem.php?pid=4911(线段树求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- HDU 3974 Assign the task (DFS序 + 线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 给你T组数据,n个节点,n-1对关系,右边的是左边的父节点,所有的值初始化为-1,然后给你q个操 ...
- hdu 3333 Turing Tree 图灵树(线段树 + 二分离散)
http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Others) ...
随机推荐
- 在IIS上SSL的部署和启动SSL安全【转】
在这次的项目中遇见了这个问题,之前我并懂了不了多少,只对了SSL和HTTPS理论了解.但并不知道在实际中如何运行.经过自己在网上查阅一番,最后靠自己解决了这个问题,现在在这里和大家分享一下.如果写的有 ...
- boost并发编程boost::atomic
三个用于并发编程的组件: atomic,thread,asio(用于同步和异步io操作) atomic atomic,封装了不同计算机硬件的底层操作原语,提供了跨平台的原子操作功能,解决并发竞争读 ...
- [转]QT QDateTime类、QTimer类
QDateTime类,头文件#include <QDateTime> 可以使用QDateTime类来获得系统时间.通过QDateTime::currentDateTime()来获取本地系统 ...
- ListPopupWindow 列表弹窗 常见弹窗区别
案例 private void showPopupWindow(final Context context, @NonNull View anchorView) { final String[] po ...
- Matplotlib绘图双纵坐标轴设置及控制设置时间格式
双y轴坐标轴图 今天利用matplotlib绘图,想要完成一个双坐标格式的图. fig=plt.figure(figsize=(20,15)) ax1=fig.add_subplot(111) ax1 ...
- Java奇淫巧技之Lombok
http://blog.csdn.net/ghsau/article/details/52334762
- 大数据开发实战:Hadoop数据仓库开发实战
1.Hadoop数据仓库架构设计 如上图. ODS(Operation Data Store)层:ODS层通常也被称为准备区(Staging area),它们是后续数据仓库层(即基于Kimball维度 ...
- [NL系列] RNN & LSTM 网络结构及应用
http://www.jianshu.com/p/f3bde26febed/ 这篇是 The Unreasonable Effectiveness of Recurrent Neural Networ ...
- NLP常用信息资源
ACL Anthology,囊括了ACL,EMNLP,CL等NLP领域重要会议和期刊的论文.http://www.aclweb.org/anthology-new/ LDC: The Linguist ...
- js 正则表验证输入
输入1-9的整数 <input type="text" class="form-control" style="width: 60px;disp ...