标签:des style http color io os java ar strong
1 10 Jan 1 2000 9 10 5 2 20 20 20 10 10 8 7 9 5 10 0 0
70Hint“Jan 1 2000 9 10” means in Jan 1st 2000 at 9 o‘clock , there‘s a consumer ordering 10 mooncakes. Maybe you should use 64-bit signed integers. The answer will fit into a 64-bit signed integer.
#include <iostream> #include <cstdio> #include <cstring> #include <string> #define Maxn 100005 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define Inf 0x7fffffff using namespace std; int cost[Maxn]; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; struct Order { string mon; int day,year,hour,num; }order[Maxn]; long long tree[Maxn<<2]; inline int leap(int year){ return (year%4==0&&year%100!=0)||year%400==0; } int get_time(string s,int y,int d,int h) { int m,ret=y*365+(y-1)/4-(y-1)/100+(y-1)/400; days[1]+=leap(y); if(s=="Jan") m=1; else if(s=="Feb") m=2; else if(s=="Mar") m=3; else if(s=="Apr") m=4; else if(s=="May") m=5; else if(s=="Jun") m=6; else if(s=="Jul") m=7; else if(s=="Aug") m=8; else if(s=="Sep") m=9; else if(s=="Oct") m=10; else if(s=="Nov") m=11; else m=12; for(int i=0;i<m-1;ret+=days[i++]); days[1]=28; return (ret+d)*24+h; } void push_up(int rt) { tree[rt]=min(tree[rt<<1],tree[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r) { tree[rt]=cost[l]; return ; } int m=(l+r)>>1; build(lson); build(rson); push_up(rt); } long long query(int L,int R,int l,int r,int rt) { if(L<=l&&R>=r) return tree[rt]; int m=(l+r)>>1; long long ans=Inf; if(L<=m) ans=min(ans,query(L,R,lson)); if(R>m) ans=min(ans,query(L,R,rson)); return ans; } int main() { int i,m,n,t,c,a,b; long long ans; freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); while(scanf("%d%d",&m,&n),m+n) { ans=0; memset(cost,0,sizeof(cost)); for(i=1;i<=m;i++) { cin>>order[i].mon; scanf("%d%d%d%d",&order[i].day,&order[i].year,&order[i].hour,&order[i].num); } scanf("%d%d",&t,&c); for(i=1;i<=n;i++) { scanf("%d",&cost[i]); cost[i]+=(n-i)*c; } build(1,n,1); for(i=1;i<=m;i++) { b=get_time(order[i].mon,order[i].year,order[i].day,order[i].hour)-get_time("Jan",2000,1,0)+1; a=b-t; int L=max(1,a);int R=min(b,n); //cout<<L<<" "<<R<<endl; ans+=(query(L,R,1,n,1)+(b-n)*c)*order[i].num; } printf("%I64d\n",ans); } return 0; }
HDU 4122 Alice's mooncake shop
标签:des style http color io os java ar strong
原文地址:http://blog.csdn.net/hqu_fritz/article/details/39374261