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) ...
随机推荐
- 7.5 zookeeper客户端curator的基本使用 + zkui
使用zookeeper原生API实现一些复杂的东西比较麻烦.所以,出现了两款比较好的开源客户端,对zookeeper的原生API进行了包装:zkClient和curator.后者是Netflix出版的 ...
- 7.3 netty3基本使用
由于dubbo默认使用的是netty3进行通信的,这里简单的列出一个netty3通信的例子. 一 server端 1 Server package com.hulk.netty.server; imp ...
- [leetcode]Regular Expression Matching @ Python
原题地址:https://oj.leetcode.com/problems/regular-expression-matching/ 题意: Implement regular expression ...
- 不得不知的ES6十大特性
ES6(ECMAScript2015)的出现,无疑给前端开发人员带来了新的惊喜,它包含了一些很棒的新特性,可以更加方便的实现很多复杂的操作,提高开发人员的效率. 本文主要针对ES6做一个简要介绍. 主 ...
- Laravel Composer 脚本
composer update --no-scripts 执行静态文件 composer dump-autoload 文件映射
- Mac系统下编译支持Android平台的最新X264编码器
Mac系统下编译支持Android平台的最新X264编码器 原文来自 http://www.mingjianhua.com,转载请注明出处 1.首先去官网下载最新的x264源代码,解压到任意目录 ht ...
- JAVA-安装apache tomcat服务器
下载地址:http://tomcat.apache.org/ 选择需要下载的版本 下载windows service installer,找到文件双击进行安装 next i agree next ne ...
- 简单实现http proxy server怎么实现?
原文:https://blog.csdn.net/dolphin98629/article/details/54599850 简单实现http proxy server怎么实现?
- Multiple Instance .NET Windows Service
It's not readily apparent how to install a Windows Service multiple times on a single machine. At fi ...
- 启动项目时出现Not a JAR.......Find JAR........一指循环就是起不来
出现问题原因就是mapper的映射文件有问题,里面的返回类型如是实体找不到或者找重复的就会这样 解决办法就是:确保在用的实体(路径)能找到,切记不能有重名的实体