• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C小加

            厚德 博學 求真 至善 The bright moon and breeze
            posts - 145, comments - 195, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            foj 2077 The tallest tree (弱爆了)

            Posted on 2012-03-27 09:24 C小加 閱讀(1095) 評論(1)  編輯 收藏 引用 所屬分類: 解題報告

            看了解題報告之后我在想,為什么我會傻傻的去把每一天的高度都求出來。。。。

             

            詢問哪一天就求出哪一天的高度,把天數排一下序可以在求的過程中刪掉高度和增長速度都小的樹。時間復雜度<=O(m*n)

            #include<iostream>
            #include<cstdio>
            #include<cstring>
            #include<algorithm>
            using namespace std;
            typedef long long ll;
            const int MAXM=100003;
            typedef struct
            {
                ll high,add;//高度和增長速度
            }Tree;
            Tree tree[MAXM];
            ll day[MAXM];//實際的數天
            ll sday[MAXM];//排序后的天數
            ll ans[MAXM];//結果

            int main()
            {
                int n,m;
                while(scanf("%d %d",&n,&m)!=EOF)
                {
                    for(int i=0;i<n;++i)
                    {
                        scanf("%lld %lld",&tree[i].high,&tree[i].add);
                    }
                    for(int i=0;i<m;++i)
                    {
                        scanf("%lld",day+i);
                        sday[i]=day[i];
                    }
                    sort(sday,sday+m);//天數從小到大排序
                    memset(ans,0,sizeof(ans));
                    Tree tmax;
                    for(int i=0;i<m;++i)//枚舉排序后的天數
                    {
                        tmax.high=tree[0].high+sday[i]*tree[0].add;
                        tmax.add=tree[0].add;
                        int pos=1;
                        for(int j=1;j<n;++j)//枚舉每一顆樹
                        {
                            Tree temp=tree[j];
                            temp.high+=sday[i]*tree[j].add;
                            if( !(tmax.high>=temp.high&&tmax.add>=temp.add) )//如果第j棵樹在sday[i]的高度和增長速度都小于某棵樹,則舍棄第j棵樹
                            {
                                tree[pos++]=tree[j];
                            }
                            //找到在sday[i]時刻高度最大的樹
                            if(tmax.high<temp.high)
                            {
                                tmax=temp;
                            }
                        }
                        n=pos;
                        ans[ sday[i] ]=tmax.high;
                    }

                    for(int i=0;i<m;++i)
                        printf("%lld\n",ans[ day[i] ]);

                }

                return 0;
            }

             

            Feedback

            # re: foj 2077 The tallest tree (弱爆了)  回復  更多評論   

            2012-03-27 09:39 by tb
            呵呵
            国产精品一区二区久久不卡| 久久精品中文无码资源站| 久久夜色精品国产噜噜麻豆| 久久99久久99小草精品免视看| 国产精品成人精品久久久| 国产美女亚洲精品久久久综合| 久久国产色AV免费观看| 日本五月天婷久久网站| 中文字幕成人精品久久不卡| 伊人久久大香线蕉综合Av | 激情五月综合综合久久69| 人妻精品久久无码专区精东影业 | 香蕉久久影院| 热久久国产精品| 久久国产精品无码一区二区三区 | 99久久er这里只有精品18| 国内精品久久久久影院网站 | 久久亚洲精品成人av无码网站| 久久精品国产99国产精偷 | 久久久久久免费一区二区三区| 三级韩国一区久久二区综合| 久久福利青草精品资源站免费| 东方aⅴ免费观看久久av| 国内精品久久久久久久涩爱| 日本福利片国产午夜久久| 久久久久亚洲AV无码麻豆| yy6080久久| 狠狠色丁香久久婷婷综合_中| 久久99精品九九九久久婷婷| 久久99国产精品久久99| 激情伊人五月天久久综合| 天堂久久天堂AV色综合| 国产精品毛片久久久久久久| 久久精品国产清自在天天线| 日韩十八禁一区二区久久| 国产亚州精品女人久久久久久| 国产成人久久激情91| 久久久久久免费一区二区三区 | 国内精品伊人久久久久777| 2021国产精品久久精品| 久久这里有精品|