poj 1042 Gone Fishing

按照题目,如果一条鱼都钓不到的话也要在第一个湖等到时间完。因为这个wa了好几次……

/*
 * Author: stormdpzh
 * POJ: 1042 Gone Fishing
 * Time: 2012/5/7 19:22:56
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>

#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define out(n) printf("%d\n", n)
#define wh(n) while(scanf("%d", &n) != EOF)
#define whz(n) while(scanf("%d", &n) != EOF && n != 0)
#define lint long long

using namespace std;

const int MaxN = 30;

int f[MaxN], d[MaxN], t[MaxN];
int tmpf[MaxN], cost_t[MaxN], cost_t1[MaxN];
int fish;
int n, h;

void solve()
{    
    int total_time = h * 60 / 5;
    fish = 0;
    memset(cost_t1, 0, sizeof(cost_t1));
    repf(i, 1, n) {
        memcpy(tmpf, f, sizeof(f));
        memset(cost_t, 0, sizeof(cost_t));
        int tmpt = h * 60 / 5;
        int sumf = 0;
        for(int j = 1; j < i; j++)
            tmpt -= t[j];
        int tmp_total_time = tmpt;
        while(tmpt > 0) {
            bool flag = false;
            int maxf = 0, index;
            repf(j, 1, i) {
                if(tmpf[j] > maxf) {
                    maxf = tmpf[j];
                    index = j;
                    flag = true;
                }
            }
            if(flag) {
                cost_t[index] += 1;
                tmpf[index] -= d[index];
                sumf += maxf;
            }
            tmpt -= 1;
        }
        if(sumf > fish) {
            fish = sumf;
            memcpy(cost_t1, cost_t, sizeof(cost_t));
            total_time = tmp_total_time;
        }
    }
    int cost_time = 0;
    repf(i, 2, n)
        cost_time += cost_t1[i];
    cost_t1[1] = total_time - cost_time;
}

int main()
{
    //freopen("data.in", "r", stdin);
    whz(n) {
        scanf("%d", &h);
        repf(i, 1, n)
            scanf("%d", &f[i]);
        repf(i, 1, n)
            scanf("%d", &d[i]);
        repf(i, 1, n - 1)
            scanf("%d", &t[i]);

        solve();

        repf(i, 1, n) {
            if(i == 1)
                printf("%d", cost_t1[i] * 5);
            else
                printf(", %d", cost_t1[i] * 5);
        }
        printf("\n");
        printf("Number of fish expected: %d\n\n", fish);
    }

    return 0;
}


你可能感兴趣的:(poj 1042 Gone Fishing)