UVA 757

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <queue>

using namespace std;
#define MAXN 30
int ans[MAXN], tmp[MAXN];

int h, n;
struct node
{
    int no, rate, cut, time;
    friend bool operator <( const node&a, const node &b)
    {
        if(a.rate != b.rate)
         return a.rate < b.rate;
        return a.no > b.no;
    }

}arr[MAXN];

priority_queue<node>que;


void fan( )
{
    int maxsum = -10000;
    for( int i = 0; i < n; i++)
    {
       while(!que.empty()) que.pop();
       for(int j = 0; j <= i; j++)  que.push(arr[j]);

       int lefttime = h*60 - arr[i].time, sum = 0;
       memset(tmp, 0, sizeof(tmp));

       while(lefttime > 0)
       {
           node temp = que.top();
           que.pop();

           if(temp.rate <= 0) break;

           sum += temp.rate;
           temp.rate -= temp.cut;
           tmp[temp.no] += 5;

           que.push(temp);
           lefttime -= 5;
       }

      if(lefttime > 0)
       tmp[0] += lefttime;

      if(sum > maxsum)
      {
          maxsum = sum;
          for( int j = 0; j < n; j++)
           ans[j] = tmp[j];
      }

    }
    printf("%d",ans[0]);
    for(int i = 1; i<n; ++i)
        printf(", %d",ans[i]);
    printf("\n");
    printf("Number of fish expected: %d\n", maxsum);
}


int main()
{
     bool flag = false;
     while(scanf("%d",&n) != EOF && n)
     {
         scanf("%d",&h);
         for( int i = 0; i < n; i++)
          {
             scanf("%d",&arr[i].rate);
             arr[i].no = i;
          }
         for( int i = 0; i < n; i++)
           scanf("%d",&arr[i].cut);
         arr[0].time = 0;
         for( int i = 1; i < n; i++)
         {
             scanf("%d",&arr[i].time);
             arr[i].time = arr[i-1].time + arr[i].time * 5;
         }
         if(flag)  printf("\n");
         flag = true;
         fan();
     }
     return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值