貪心/poj 1042 Gone Fishing

來源:互聯網
上載者:User

標籤:style   blog   io   color   sp   for   on   div   log   

 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 struct node 5 { 6     int d; 7     int fish; 8     int ans; 9 };10 node a[30],b[30];11 int t[30];12 int n,h,sum;13 int main()14 {15     scanf("%d",&n);16     while (n!=0)17     {18         memset(a,0,sizeof(a));19         memset(t,0,sizeof(t));20         scanf("%d",&h);21         h=h*12;22         for (int i=1;i<=n;i++) scanf("%d",&a[i].fish);23         for (int i=1;i<=n;i++) scanf("%d",&a[i].d);24         for (int i=1;i<n;i++)scanf("%d",&t[i]);25         sum=-1;26         for (int stop=1;stop<=n;stop++)27         {28             memset(b,0,sizeof(b));29             int time=h;30             int answer=0;31             for (int i=1;i<=stop;i++)32             {33                 b[i].fish=a[i].fish;34             }35             for (int i=1;i<stop;i++) time-=t[i];36 37             for (int rest=time;rest>0;rest--)38             {39 40                 int fishmax=1;41                 for (int i=2;i<=stop;i++)42                     if (b[fishmax].fish<b[i].fish) fishmax=i;43 44                 answer+=b[fishmax].fish;45                 b[fishmax].ans++;46                 b[fishmax].fish-=a[fishmax].d;47                 if (b[fishmax].fish<0) b[fishmax].fish=0;48             }49             if (answer>sum)50             {51                 sum=answer;52                 for (int i=1;i<=n;i++) a[i].ans=b[i].ans;53             }54         }55         for (int i=1;i<n;i++) printf("%d, ",a[i].ans*5);56         printf("%d\n",a[n].ans*5);57         printf("Number of fish expected: %d\n\n",sum);58         scanf("%d",&n);59     }60     return 0;61 }

 

貪心/poj 1042 Gone Fishing

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.