• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            poj 1042 Gone Fishing(貪心+枚舉)

            Posted on 2012-04-06 08:13 C小加 閱讀(1863) 評論(3)  編輯 收藏 引用 所屬分類: 解題報告

            第一次WA,發現輸出格式不對,改掉。

            第二次WA,對結果相等的情況沒有考慮,改掉。

            第三次AC。

            題意和題解見黑書P13。

            需要注意的是要枚舉從第一個湖走到最后一個湖的每一種情況,對結果相等這種情況做特殊處理。

            #include<iostream>
            #include<cstdio>
            #include<cstring>
            using namespace std;
            const int MAXM=30;
            int n,h;
            int f[MAXM],d[MAXM],t[MAXM];
            int each_time[MAXM];
            int ans_time[MAXM];
            int tf[MAXM];
            int ans;
            //初始化
            void init()
            {
                memset(each_time,0,sizeof(each_time));
                memset(ans_time,0,sizeof(ans_time));
                ans=0;
            }
            //輸入
            bool input()
            {
                init();
                scanf("%d",&n);
                if(0==n) return false;
                scanf("%d",&h);
                for(int i=0;i<n;++i)
                {
                    scanf("%d",f+i);
                }
                for(int i=0;i<n;++i)
                {
                    scanf("%d",d+i);
                }
                for(int i=0;i<n-1;++i)
                {
                    scanf("%d",t+i);
                }
                return true;
            }

            void solve(int rem_time,int q)
            {
                int tans=0;
                memset(each_time,0,sizeof(each_time));

                memcpy(tf,f,sizeof(f));
                for(int i=0;i<rem_time;++i)//找魚的數量最多的湖
                    {
                        int pos=0,max_fish=tf[0];
                        if(q>0)
                        for(int j=1;j<=q;++j)
                        {
                            if(max_fish<tf[j])
                            {
                                max_fish=tf[j];
                                pos=j;
                            }
                        }
                        ++each_time[pos];
                        tans+=tf[pos];
                        tf[pos]-=d[pos];
                        if(tf[pos]<0) tf[pos]=0;

                    }
                    if(tans>ans)
                    {
                        ans=tans;
                        memcpy(ans_time,each_time,sizeof(each_time));
                    }
                    else if(tans==ans)//細節,答案相等時做的處理。
                    {
                        int i;
                        for(i=0;i<n;++i)
                        {
                            if(each_time[i]!=ans_time[i]) break;
                        }
                        if(each_time[i]>ans_time[i])
                        {
                            memcpy(ans_time,each_time,sizeof(each_time));
                        }
                    }
            }

            void print()
            {
                printf("%d",ans_time[0]*5);
                for(int i=1;i<n;i++)
                {
                    printf(", %d",ans_time[i]*5);
                }
                printf("\nNumber of fish expected: %d\n\n",ans);
            }
            int main()
            {
               // freopen("in.txt","r",stdin);
               
            // freopen("out2.txt","w",stdout);
                while(input())
                {
                    int rem_time=h*60;
                    rem_time/=5;
                    solve(rem_time,0);
                    for(int i=0;i<n-1;++i)//枚舉每個湖
                    {
                        rem_time-=t[i];
                        solve(rem_time,i+1);
                    }
                    print();

                }

                return 0;
            }

            Feedback

            # re: poj 1042 Gone Fishing(貪心+枚舉)  回復  更多評論   

            2012-04-09 17:32 by coreBugZJ
            曾經ACM的路過。。。

            # re: poj 1042 Gone Fishing(貪心+枚舉)  回復  更多評論   

            2012-04-10 08:36 by C小加
            我也快結束ACM生涯了@coreBugZJ

            # re: poj 1042 Gone Fishing(貪心+枚舉)  回復  更多評論   

            2012-04-19 17:07 by SunRise_at
            我已經結束了啊。。。@C小加
            久久精品中文无码资源站| 亚洲精品99久久久久中文字幕 | 激情伊人五月天久久综合| 久久涩综合| 合区精品久久久中文字幕一区| 亚洲狠狠综合久久| 99久久精品无码一区二区毛片 | 久久99国内精品自在现线| 一本一本久久a久久综合精品蜜桃| 久久影院午夜理论片无码| 欧美午夜精品久久久久久浪潮| 久久免费99精品国产自在现线 | 久久国产精品视频| 久久精品国产欧美日韩| 日韩亚洲国产综合久久久| 久久亚洲AV成人无码软件 | 熟妇人妻久久中文字幕| 麻豆成人久久精品二区三区免费 | 9久久9久久精品| 伊人久久大香线焦综合四虎| 国产农村妇女毛片精品久久| 久久青青草原精品国产软件 | 午夜精品久久久久久99热| 日产精品99久久久久久| 99精品久久久久中文字幕| 久久国产综合精品五月天| 久久天天躁狠狠躁夜夜avapp| 久久亚洲中文字幕精品有坂深雪| 精品国产91久久久久久久| 久久青青草原亚洲av无码| 亚洲AV无码成人网站久久精品大| 久久久噜噜噜www成人网| 久久久久久久综合日本| 色偷偷88888欧美精品久久久 | 久久亚洲精品无码播放| 亚洲午夜久久久久久久久电影网 | 亚洲伊人久久大香线蕉苏妲己| 久久久99精品成人片中文字幕| 亚洲午夜久久久影院| 久久久久99精品成人片三人毛片| 亚洲伊人久久精品影院|