题目大意:一个月饼店开m个小时(24小时营业),只在整点做月饼,做月饼的能力非常强。现在只需要考虑成本的问题。给m个cost值,cost[i]表示第i个小时做1个月饼的代价。
水题嘛,写写写T^T
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <queue> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; template <class T> inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } int MON[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,\ 31,29,31,30,31,30,31,31,30,31,30,31 }; int YEAR[3000];//year[i]表示 到第i年结束时的小时数 bool run(int x){if(x%400 == 0)return true; return (x%100) && x%4==0;} void init(){ memset(YEAR, 0, sizeof YEAR); for(int i = 2000; i < 3000; i++) { YEAR[i] = YEAR[i-1]; YEAR[i] += 8760; if(run(i)) YEAR[i] += 24; } for(int i = 0; i < 2; i++) for(int j = 0; j < 12; j++) MON[i][j] *= 24; } int find_yue(string str){ if(str=="Jan")return 1; if(str=="Feb")return 2; if(str=="Mar")return 3; if(str=="Apr")return 4; if(str=="May")return 5; if(str=="Jun")return 6; if(str=="Jul")return 7; if(str=="Aug")return 8; if(str=="Sep")return 9; if(str=="Oct")return 10; if(str=="Nov")return 11; if(str=="Dec")return 12; return -100000000; } const int N = 50010; int n, m, s, t, cost[100010]; struct Buy{ int tim, r; }buy[2555]; void input(){ string mon; for(int i = 1, day, year, hour; i <= n; i++) { cin>>mon; rd(day); rd(year); rd(hour); rd(buy[i].r); buy[i].tim = YEAR[year-1]; int cur = run(year); int yue = find_yue(mon) -1; for(int j = 0; j < yue; j++) buy[i].tim += MON[cur][j]; buy[i].tim += 24*(day-1); buy[i].tim += hour; } rd(t); rd(s); for(int i = 0; i < m; i++)rd(cost[i]); // for(int i = 1; i <= n; i++)printf("(%d,%d)\n", buy[i].tim, buy[i].r); } struct node { int id; ll v; node() {} node(int _id, ll _v) { id = _id; v = _v; } friend bool operator < (const node& j, const node& i) { if (i.v!=j.v) return i.v<j.v; else return i.id<j.id; } }; priority_queue<node>Q; void work() { ll ans = 0, x = 0; while (!Q.empty()) Q.pop(); int idx = 1; for (int i = 0; i < m; ++i) { Q.push(node(i, cost[i]-x)); while (!Q.empty() && i-Q.top().id>t) Q.pop(); while (idx<=n&&buy[idx].tim==i) { ans += (ll)buy[idx].r * (cost[Q.top().id] + (ll)(i-Q.top().id)*s); //ans += (ll)buy[idx].r * (Q.top().v+x); ++idx; } if (idx == n+1) break; x += s; } while (idx<=n) { while (!Q.empty() && buy[idx].tim-Q.top().id>t) Q.pop(); ans += (ll)buy[idx].r * (cost[Q.top().id] + (ll)(buy[idx].tim-Q.top().id)*s); ++idx; } pt(ans); putchar('\n'); } int main() { init(); while(cin>>n>>m, n+m) { input(); work(); } return 0; } /* 1 4 Jan 1 2000 7 10 3 10 1 20 200 10 */