Topic Link http://acm.hdu.edu.cn/showproblem.php?pid=4122
Test instructions to the effect that Alice opened a moon cake shop, can receive N to make moon cakes orders, and Alice only in the first hour from January 1, 2000 0 o'clock to start the last m hours of moon cakes, and only on the whole point
When making moon cakes, and do not take time to do mooncakes, that is, instant can do super many mooncakes, and each moon cake has a T-hour shelf life, each moon cake to save every hour to spend S yuan, and in can
Do the moon cakes in M hours, different hours to do the moon cakes are also different, each order has a delivery order mm time, a certain date of the year, the delivery of the order required for the R Moon Cakes, to complete all orders
The minimum amount of money spent.
Think about it, unify the time to start from the beginning of the hour, can be seen in a time axis, n orders is n a specific node, is to find each node in the first T-point of the minimum cost
Similar to the monotone queue, the cost of comparing the smallest single moon cake in the range is related to the amount of time it takes to save the moon cake, in addition to its own price.
The longer you save, the more you spend, so you have to store two variables, prices, and times in the queue.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 using namespacestd;6typedefLong Longll;7 8typedefstructpoint{9 ll Need,time;Ten }; One ADeque<point>Q; -Queue<point>p; - Charyj[Ten]; the intnum[ the]={0, to, -, to, -, to, -, to, to, -, to, -, to}; - - intRun (ll x) { - if((%4==0&&x% -!=0)|| X% -==0)return 0; + Else return 1; - } + A ll _moon () { at if(strcmp (YJ,"Jan")==0)return 1; - Else if(strcmp (YJ,"Feb")==0)return 2; - Else if(strcmp (YJ,"Mar")==0)return 3; - Else if(strcmp (YJ,"APR")==0)return 4; - Else if(strcmp (YJ," May")==0)return 5; - Else if(strcmp (YJ,"June")==0)return 6; in Else if(strcmp (YJ,"Jul")==0)return 7; - Else if(strcmp (YJ," the")==0)return 8; to Else if(strcmp (YJ,"Sep")==0)return 9; + Else if(strcmp (YJ,"Oct")==0)return Ten; - Else if(strcmp (YJ,"Nov")==0)return One; the Else return A; * } $ Panax Notoginseng ll _time () { - ll A,b,c,i; thescanf"%s%i64d%i64d%i64d",yj,&a,&b,&c); +ll D=_moon (), h=0; A for(i= -; i<b;i++){ the if(Run (i)) h+=365* -; + Elseh+=366* -; - } $ for(i=1; i<d;i++){ $ if(i==2&&!run (b)) h+= in* -; - Elseh+=num[i]* -; - } theh+= (A-1)* -; - returnH +C;Wuyi } the - intMain () Wu { - ll N,m,i,t,s,x; About Point S1; $ while(~SCANF ("%i64d%i64d", &n,&m), n+m) { - q.clear (); - for(i=1; i<=n;i++){ -S1.time=_time (); Ascanf"%i64d",&s1.need); + P.push (S1); the } - /*For (i=1;i<=n;i++) { $ printf ("%i64d%i64d\n", P.front (). Need,p.front (). time); the P.pop (); the }*/ thescanf"%i64d%i64d",&t,&s); thell ans=0; - for(i=0; i<m;i++){ inscanf"%i64d",&x); the while(!q.empty () &&x<=q.back (). need+ (I-q.back (). Time) *s) the Q.pop_back (); AboutS1.need=x;s1.time=i; the Q.push_back (S1); the while(!p.empty () &&i==P.front (). Time) { the while(!q.empty () &&i>q.front (). time+t) + Q.pop_front (); -ans+= ((I-q.front (). Time) *s+q.front (). Need) *P.front (). need; the P.pop ();Bayi } the } theprintf"%i64d\n", ans); - } - return 0; the}
HDU 4122 Alice ' s mooncake shop