HDU 4122 Alice's mooncake shop (单调队列/线段树)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4122
题意:好难读懂,读懂了也好难描述,亲们就自己凑合看看题意把
题解:开始计算每个日期到2000/1/1日0点有多少个小时,然后求出每个小时的时候每个的最小单价(包括成本+储存费用)
使用单调队列,维护队列,使之到i 生产的最优
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; #define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s) scanf("%s",s)
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d %d\n",a,b)
#define mset(a,b) memset(a,b,sizeof(a))
#define forb(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i<=b;i++) typedef __int64 LL;
const int N=110001;
const int M=1000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-7; LL n,m,s,t;
char ss[100];
int mm[13],yy[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
map<string,int> mp;
struct node
{
int t,num;
}q[3333*4],order[3333]; bool isrun(int y)
{
if(y%400==0||(y%4==0&&y%100!=0))
return true;
return false;
} int run(int y1,int y2)
{
int num=0;
for(int i=y1;i<y2;i++)
if(i%400==0||(i%4==0&&i%100!=0))
num++;
return num;
} int main()
{
mm[0]=0;
for(int i=1;i<=12;i++)
mm[i]=mm[i-1]+yy[i];
mp["Jan"]=1;
mp["Feb"]=2;
mp["Mar"]=3;
mp["Apr"]=4;
mp["May"]=5;
mp["Jun"]=6;
mp["Jul"]=7;
mp["Aug"]=8;
mp["Sep"]=9;
mp["Oct"]=10;
mp["Nov"]=11;
mp["Dec"]=12; while(scanf("%I64d%I64d",&n,&m)&&(n+m))
{
for(int i=0;i<n;i++)
{
string ss;
int ri,nian,shi,ge;
cin>>ss;
scanf("%d%d%d%d",&ri,&nian,&shi,&order[i].num);
int yue=mp[ss];
int sum=(nian-2000)*365+run(2000,nian);
sum+=mm[yue-1]+ri-1;
if(yue>2&&isrun(nian)) sum++;
order[i].t=sum*24+shi;
}
int top=0,tail=0,p=0,t,s;
LL sum=0;
scanf("%d%d",&t,&s);
for(int i=0;i<m;++i)
{
int a;
scanf("%d",&a);
while(top<tail && q[tail-1].num+(i-q[tail-1].t)*s>=a)--tail;
q[tail].num=a,q[tail++].t=i;
while(p<n && i == order[p].t)
{
while(q[top].t+t<i)++top;
sum+=(q[top].num+(i-q[top].t)*s)*order[p++].num;
}
}
printf("%I64d\n",sum);
}
return 0;
}
/*
1 10
Jan 1 2000 9 10
5 2
20
20
20
10
10
8
7
9
5
10
0 0
*/
HDU 4122 Alice's mooncake shop (单调队列/线段树)的更多相关文章
- 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 4122 Alice's mooncake shop
单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order. 呢,我就当成严格上升的序列了,于是就各种错.测试 ...
- HDU 4122 Alice's mooncake shop --RMQ
题意: 一个月饼店做月饼,总营业时间m小时,只能在整点做月饼,可以做无限个,不过在不同的时间做月饼的话每个月饼的花费是不一样的,假设即为cost[i],再给n个订单,即为在某个时间要多少个月饼,时间从 ...
- poj3162 树形dp|树的直径 + 双单调队列|线段树,好题啊
题解链接:https://blog.csdn.net/shiqi_614/article/details/8105149 用树形dp是超时的,, /* 先求出每个点可以跑的最长距离dp[i][0|1] ...
- [洛谷P1886]滑动窗口 (单调队列)(线段树)
---恢复内容开始--- 这是很好的一道题 题目描述: 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口. 现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的 ...
- newcoder H肥猪(单调队列 / 线段树)题解
题意: 小B来到了一个异世界,成为了肥猪之王. 在这个异世界,共有n种肥猪,编号分别为1,...,n. 小B希望集齐这n种肥猪. 召集肥猪有两种方式: 1. 花费a[i]的金币召唤一只编号为i的肥猪. ...
- POJ 2823 Sliding Window(单调队列 || 线段树)题解
题意:求每个长度为k的数组的最大值和最小值 思路: 1.用线段树创建维护最大值和最小值,遍历询问,简单复习了一下...有点手生 2.单调队列: 可以看一下详解 单调队列顾名思义就是一个单调递增或者递减 ...
随机推荐
- java实验7-多线程编程
1 利用Thread和Runnable创建线程 [实验目的] (1)理解用实现Runnable接口的方法实现多线程. (2)掌握线程优先级的设置. (3)加深对线程状态转换的理解. [实验要求] 要求 ...
- js中indexof()简单使用
indexOf()方法返回某个指定的字符串值在字符串中首次出现的位置. stringObject.indexOf(searchvalue,fromindex):indexOf()方法对大小写敏感如果要 ...
- 支持多QQ登录的软件
支持多QQ登录,批量加好友,批量回复QQ消息,当然也能接收 下载链接:多QQ登录软件
- ncsim仿真VHDL
ncsim仿真VHDL 1.文件列表 ctrl.vhd design_io.vhd tb.vhd compile.nc simulate.nc ./shm/shmtb.tcl 2. Compile你的 ...
- SQL数据库注入防范 ASP.NET Globle警告
在项目中的Global.asax页面代码中加下面的代码,就可以有效的防范简单的SQL注入. protected void Application_BeginRequest(Object sender, ...
- Windows命令行(DOS命令)教程-8 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_7.html
15. pass [功能] 设定DOS寻找.COM..EXE..BAT文件的所在目录 [格式] path=[[drive:]path[;-]]或path [说明] 只打path没有参数时,只显示环境变 ...
- C#拖动自己的定义标题栏(panel)以及实现窗体拖动关闭和最小化
//没有标题 this.FormBorderStyle = FormBorderStyle.None; //任务栏不显示 this.ShowInTaskbar = false; //实现拖动 1.在窗 ...
- 系统报错 hppatusg01
下载DLL 放在C:\Windows\SysWOW64(64位系统)或C:\Windows\System32(32位系统) 下载地址 https://yunpan.cn/cBB4Q6czDKyqt ...
- 文件:因为懂你,所以永恒 - 零基础入门学习Python028
文件:因为懂你,所以永恒 让编程改变世界 Change the world by program 因为懂你,所以永恒 大多数的程序都遵循着:输入->处理->输出的模型,首先接受输入数据,然 ...
- 一个人的旅行--hdu2066
一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...