hdu 4122 Alice's mooncake shop (線段樹)

來源:互聯網
上載者:User

標籤:blog   get   2014   os   name   c   

題目大意:

一個月餅店每個小時做出月餅的花費不一樣。

儲存起來要錢,最多存多久。問你把所有訂單做完的最少花費。


思路分析:

ans = segma( num[]*(cost[] + (i-j)*s) )

整理一下會發現式子就是  

cost[]-j*s + i*s 

對於每一個訂單,我們把i拿出來分析

所以也就用cost - j*s 建樹。

然後在儲存期間找到最小的花費就行了。


#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <string>#define lson num<<1,s,mid#define rson num<<1|1,mid+1,e#define maxn 2555#define maxm 100005#define inf 0x3f3f3f3fusing namespace std;typedef long long LL;int n,m;int days[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},                {0,31,29,31,30,31,30,31,31,30,31,30,31}};string tab[] = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};LL tre[maxm<<2];int getmonth(string x){    for(int i=1;i<=12;i++)    if(x==tab[i])return i;}bool leap(int x){    if(((x%4==0) && x%100!=0) || x%400==0)return true;    return false;}LL gethour(int month,int day,int year,int hour){    LL res=day-1;    int is=leap(year);    for(int i=1;i<month;i++)res+=days[is][i];    for(int i=2000;i<year;i++)    res+=365+leap(i);    res*=24;    res+=hour+1;    return res;}void build(int num,int s,int e){    tre[num]=inf;    if(s==e)return;    int mid=(s+e)>>1;    build(lson);    build(rson);}void update(int num,int s,int e,int pos,LL val){    if(s==e)    {        tre[num]=val;        return;    }    int mid=(s+e)>>1;    if(pos<=mid)update(lson,pos,val);    else update(rson,pos,val);    tre[num]=min(tre[num<<1],tre[num<<1|1]);}LL query(int num,int s,int e,int l,int r){    if(l<=s && r>=e)    {        return tre[num];    }    int mid=(s+e)>>1;    if(r<=mid)return query(lson,l,r);    else if(l>mid)return query(rson,l,r);    else return min(query(lson,l,mid),query(rson,mid+1,r));}string tmp;LL num[maxn];LL cost[maxm];LL time[maxm];int main(){    while(cin>>n>>m)    {        if(n==0 && m==0)break;        for(int i=1;i<=n;i++)        {            int d,y,h,Num;            cin>>tmp;            cin>>d>>y>>h>>Num;            num[i]=Num;            time[i]=gethour(getmonth(tmp),d,y,h);        }        LL S,T;        build(1,1,m);        cin>>T>>S;        for(int i=1;i<=m;i++)        {            cin>>cost[i];            cost[i]-=i*S;            update(1,1,m,i,cost[i]);        }        LL ans=0;        for(int i=1;i<=n;i++)        {            if(time[i]>m)break;            ans+=num[i]*(query(1,1,m,max(1LL,time[i]-T+1),time[i])+time[i]*S);        }        cout<<ans<<endl;    }    return 0;}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.