其他分享
首页 > 其他分享> > poj 1042(分类讨论,模拟)

poj 1042(分类讨论,模拟)

作者:互联网

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
    int i,j,k,n,h,h_t,f[30],d[30],sheng[30],t[30],ans_t[30][30],sum_fish[30];
    int st,sum_t,sum_fish_t,sum_fish_i,tmp,tmp_i;
    while(scanf("%d",&n)==1&&n){
        scanf("%d",&h);
        for(i=1;i<=n;i++){
            scanf("%d",&f[i]);
        }
        for(i=1;i<=n;i++){
            scanf("%d",&d[i]);
        }
        for(i=1;i<n;i++){
            scanf("%d",&t[i]);
        }
        memset(ans_t,0,sizeof ans_t);
        for(k=1;k<=n;k++){
            h_t = 12*h;//共多少个5分钟
            for(st=0,i=1;i<k;i++){
                st += t[i];
            } 
            for(i=1;i<=k;i++){
                sheng[i] = f[i];
            }
            sum_t = h_t-st;
            sum_fish[k] = 0;
            for(i=1;i<=sum_t;i++){
                tmp = sheng[1];
                tmp_i = 1;
                for(j=2;j<=k;j++){
                    if(tmp<sheng[j]){
                        tmp_i = j;
                        tmp = sheng[j];
                    }
                }
                 sum_fish[k] += sheng[tmp_i];
                ans_t[k][tmp_i]++;
                if(sheng[tmp_i]-d[tmp_i]<0)sheng[tmp_i] = 0;
                else sheng[tmp_i] -= d[tmp_i];
            }
//            for(i=1;i<=n;i++){
//                cout<<k<<" "<<i<<" "<<ans_t[k][i]<<endl;
//            }
//            cout<<sum_fish[k]<<endl;
        }
        sum_fish_t = sum_fish[1];
        sum_fish_i = 1;
        for(k=2;k<=n;k++){
            if(sum_fish_t<sum_fish[k]){
                sum_fish_i = k;
                sum_fish_t = sum_fish[k];
            }
        }
        printf("%d",ans_t[sum_fish_i][1]*5);
        for(i=2;i<=n;i++){
            printf(", %d",ans_t[sum_fish_i][i]*5);
        }
        printf("\nNumber of fish expected: %d\n\n",sum_fish_t);
    }
    return 0;
}

 

标签:tmp,1042,int,sum,30,poj,include,fish,模拟
来源: https://www.cnblogs.com/stevenzrx/p/15141625.html