现在的位置: 首页 > 综合 > 正文

757 – Gone Fishing

2012年04月28日 ⁄ 综合 ⁄ 共 941字 ⁄ 字号 评论关闭
描述:暴力+贪心,先定向选择依次只能到达第一个湖、第二个湖……最后一个湖,就会变成选择最优解问题,选择和最大的就可以了,注意有可能数据都是为零的时候,这是把所有的时间都用在第一个湖就可以了
#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;
}

抱歉!评论已关闭.