uva 757 - Gone Fishing

来源:互联网 发布:ubuntu 64位下载 编辑:程序博客网 时间:2024/05/17 20:27
#include <cstdio>#include <cstring>#include <cctype>#include <cstdlib>#include <queue>#include <stack>#include <cmath>#include <string>#include <iostream>#include <map>#include <algorithm>using namespace std;#define maxn 25 + 10#define INF 2100000000#define ll long longstruct node{    int no, f, d, t;    bool operator < (const node &rha) const{        if(f == rha.f) return no > rha.no;        else return f < rha.f;    }}l[maxn];priority_queue<node> q;int main(){    int n;    bool first = true;    while(scanf("%d", &n) != EOF && n)    {        if(first) first = false;        else puts("");        int h;        scanf("%d", &h);        for(int i = 0; i < n; ++i)        {            scanf("%d", &l[i].f);            l[i].no = i;        }        for(int i = 0; i < n; ++i)            scanf("%d", &l[i].d);        l[0].t = 0;        for(int i = 1; i < n; ++i)        {            scanf("%d", &l[i].t);            l[i].t += l[i-1].t;        }        int ans = -INF;        int lt[maxn], anslt[maxn];        memset(anslt, 0, sizeof(anslt));        for(int i = 0; i < n; ++i)        {            memset(lt, 0, sizeof(lt));            while(!q.empty()) q.pop();            for(int j = 0; j <= i; ++j)                q.push(l[j]);            int tottime = h*60 - l[i].t*5;            int sum = 0;            node t;            while(tottime > 0)            {                if(!q.empty()) t = q.top();                q.pop();                if(t.f <= 0) break;                sum += t.f;                t.f -= t.d;                lt[t.no] += 5;                tottime -= 5;                q.push(t);            }            if(tottime > 0) lt[0] += tottime;            if(sum > ans)            {                ans = sum;                for(int k = 0; k <= i; ++k)                    anslt[k] = lt[k];            }        }        printf("%d", anslt[0]);        for(int i = 1; i < n; ++i)            printf(", %d", anslt[i]);        printf("\n");        printf("Number of fish expected: %d\n", ans);    }    return 0;}

0 0
原创粉丝点击