⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gone fishing.cpp

📁 ACM里面一道题目
💻 CPP
字号:
//04计算机三班
//林明志
//2004374312
//ver. 1.0
//2007.12


#include<iostream>

using namespace std;

int main()

{

       int i,j,k,g,n,h,ans,tot,tt=0,f[32],d[32],t[32],now[32],tnow[32],times[32];

       while (scanf("%d",&n),n)

       {

              if (tt++)

                     printf("\n");

              scanf("%d",&h);

              h*=12;

              for (i=0;i<n;++i)

              {

                     scanf("%d",&f[i]);

                     now[i]=f[i];

              }

              for (i=0;i<n;++i)

                     scanf("%d",&d[i]);

              for (i=0;i<n-1;++i)

                     scanf("%d",&t[i]);

              memset(times,0,sizeof(times));

              for (ans=i=0;i<n&&h>0;++i)

              {

                     for (j=0;j<i;++j)

                            now[j]=f[j];

                     memset(tnow,0,sizeof(tnow));

                     for (tot=k=0;k<h;++k)

                     {

                            for (g=0,j=1;j<=i;++j)

                                   if (now[j]>now[g])

                                          g=j;

                            tot+=now[g];

                            now[g]-=d[g];

                            if (now[g]<0)

                                   now[g]=0;

                            ++tnow[g];

                     }

                     if (tot>ans)

                     {

                            ans=tot;

                            for (j=0;j<n;++j)

                                   times[j]=tnow[j];

                     }

                     else if (tot==ans)

                     {

                            for (j=0;j<n;++j)

                                   if (tnow[j]!=times[j])

                                          break;

                            if (j<n&&tnow[j]>times[j])

                                   for (g=j;g<n;++g)

                                          times[g]=tnow[g];

                     }

                     h-=t[i];

              }

              for (i=0;i<n-1;++i)

                     printf("%d, ",times[i]*5);

              printf("%d\nNumber of fish expected: %d\n",times[n-1]*5,ans);

       }

       return 0;

}










⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -