zoukankan      html  css  js  c++  java
  • 757 Gone Fishing

    描述:暴力+贪心,先定向选择依次只能到达第一个湖、第二个湖……最后一个湖,就会变成选择最优解问题,选择和最大的就可以了,注意有可能数据都是为零的时候,这是把所有的时间都用在第一个湖就可以了
    #include <cstdio>
    #include <cstring>
    int main()
    {
       // freopen("a.txt","r",stdin);
        int t[30],f[30],d[30],s[30];
        int h,n,count,p=0;
        while(scanf("%d",&n)!=EOF)
        {
            if(!n) break;
            if(p) printf("\n");
            scanf("%d",&h);
            h*=60;
            for(int i=0; i<n; i++) scanf("%d",&f[i]);
            for(int i=0; i<n; i++) scanf("%d",&d[i]);
            count=t[0]=0;
            for(int i=1; i<n; i++)
            {
                scanf("%d",&t[i]);
                t[i]=t[i]*5+t[i-1];
            }
            memset(s,0,sizeof(s));
            for(int i=0; i<n; i++)
            {
                int leave=h-t[i];
                if(leave<5) break;
                int sum=0,pos=0,temp[30],m[30],flag,c;
                for(int j=0; j<=i; j++)
                {
                    m[j]=f[j];
                    temp[j]=0;
                }
                while(leave>=5)
                {
                    flag=c=0;
                    for(int j=0; j<=i; j++)
                        if(m[j]>c)
                        {
                            c=m[j];
                            pos=j;
                            flag=1;
                        }
                    if(!flag) break;
                    temp[pos]+=5;
                    sum+=c;
                    m[pos]-=d[pos];
                    leave-=5;
                }
                if(leave>=5) temp[0]+=leave;
                if(sum>count)
                {
                    count=sum;
                    for(int j=0; j<=i; j++) s[j]=temp[j];
                }
            }
            if(!count) s[0]=h;
            printf("%d",s[0]);
            for(int i=1; i<n; i++) printf(", %d",s[i]);
            printf("\nNumber of fish expected: %d\n",count);
            p++;
        }
        return 0;
    }


  • 相关阅读:
    BZOJ 4245: [ONTAK2015]OR-XOR
    BZOJ 2535: [Noi2010]Plane 航空管制2
    COGS 2551. 新型武器
    cogs2550. 冰桥,升起来了!
    大数模板
    uva 1513(线段树)
    uva 11525(线段树)
    poj 3368(RMQ模板)
    hdu 4686 Arc of Dream(矩阵快速幂)
    poj 3321 Apple Tree(树状数组)
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2998310.html
Copyright © 2011-2022 走看看