单调队列,裸的!!坑死了,说好的“All the orders are sorted by the time in increasing order.呢,我就当成严格上升的序列了,于是就各种错。测试数据是有重复元素的!!!
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define MP make_pair
#define eps 1e-10
using namespace std;
const int N = 3333;
const int M = 111111;
int order[N], tim[N], pay[M];
char month[15][5] = {"zero", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int hav[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char mo[5];
int p[M];
int n, m, t, s, y, h, r, d;
map<string, int> mp;
void pre()
{
int i;
mp.clear();
for(i = 1; i <= 12; i ++)
{
mp[month[i]] = i;
}
}
int get_tm(int m, int d, int y, int h)
{
int ret = 0, i;
for(i = 0; i < y; i ++)
{
if(i % 4 == 0) ret += 366 * 24;
else ret += 365 * 24;
}
for(i = 1; i < m; i ++)
{
ret += hav[i] * 24;
if(i == 2 && y % 4 == 0) ret += 24;
}
ret += (d - 1) * 24 + h;
return ret;
}
void input()
{
int i, j;
for(i = 0; i < n; i ++)
{
scanf("%s%d%d%d%d", mo, &d, &y, &h, &r);
order[i] = r;
tim[i] = get_tm(mp[mo], d, y - 2000, h);
}
scanf("%d%d", &t, &s);
for(i = 0; i < m; i ++)
{
scanf("%d", &pay[i]);
}
}
void slove()
{
int l = 0, r = 0, i = 0, j = 0;
LL ans = 0;
p[r ++] = 0;
while(i < m)
{
while(pay[i] <= pay[p[r - 1]] + (i - p[r - 1]) * s && r > l) r --;
p[r ++] = i;
while(i - p[l] > t) l ++;
while(j < n && i == tim[j])ans += (pay[p[l]] + (i - p[l]) * (LL)s) * (LL)order[j], j ++;
i ++;
}
printf("%I64d\n", ans);
}
int main()
{
//freopen("input.txt", "r", stdin);
pre();
while(scanf("%d%d", &n, &m), n + m)
{
input();
slove();
}
return 0;
}
分享到:
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 1166线段树代码
HDU最全ac代码
hdu动态规划算法集锦
自己做的HDU ACM已经AC的题目
hdu题目分类
HDU图论题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
Hdu 1237 解题代码