hdu 4600 Harvest Moon

来源:互联网 发布:开淘宝c店要多少钱 编辑:程序博客网 时间:2024/06/05 18:32

牧场物语,太经典的游戏了。小时候玩一个暑假都不够的~

题意:给你一个w*h的格子,有 A种 种子,每种种子都能撒播在3*3的格子上,超出格子范围的种子无效,种子n天后成熟,就直接能收获了。有的种子收获后直接消失,然后格子又变成空的又能撒播种子了,但是有些种子可以视作永远不会消失,然后以m天为一个周期成熟收获。现在让你只能买一种种子,初始的钱为Y,给你每个种子买进一个的价格和1*1的格子成熟收获后的报酬。问D天后最多会有多少钱,你也可以什么都不买。


首先对于撒播的格子数要进行处理,比如刚开始肯定是要撒播左上角3*3的网格,但是后面由于网格不够可能就有1*3或者2*2之类的网格了,这些的处理方式就是贪心来处理,也就是让一个种子尽量撒播更多的网格数。这里尤其需要注意的是,如果右下角不能刚好撒播3*3的网格,那么我们应该先撒播右下角的网格,然后再是下面和右边的,这个自己画个图就知道了。

对于m = 0的情况是比较好考虑的,只需要每过D天处理一下,继续用当前的钱去买种子,如果种子种下当前的网格数最后得到的报酬大于种子价格,那就买进。


对于m  > 0 的情况,由于总共就D天,那我们可以直接模拟一下,每过一天判断下当前的钱能否买种子并且也要保证种子最后获得的总收获大于种子价格,如果要买进,那就给接下来将会收获得到报酬的那些天里加上获得的报酬。


#include <stdio.h>#include <string.h>#define LL __int64struct corns {    int q, p, n, m;}a[1111];int s[11] , ss[11], D, Y;LL ans , val[1002];void solve1(int i) {    LL cur = Y;    int day = 0, j;    while(day <= D) {        if(day + a[i].n <= D) {            LL tot = cur/a[i].q;            for(j = 9;j >= 1; j--) if(s[j]) {                if(j*a[i].p > a[i].q)   {                    if(tot <= s[j]) {                        cur += tot * (LL)( j*a[i].p - a[i].q );                        tot = 0;                        break;                    }                    else {                        cur += (LL)s[j] * ( j*a[i].p - a[i].q );                        tot -= s[j];                    }                }                else    break;            }        }        day += a[i].n;    }    if(cur > ans)        ans = cur;}void solve2(int i) {    int j, k, l;    memset(val, 0, sizeof(val));    LL cur = Y;    for(j = 1;j <= 9; j++)    ss[j] = s[j];    for(j=  0;j <= D; j++) {        cur += val[j];        LL tot = cur/a[i].q;        for(k = 9;k >= 1; k--) if(ss[k]){            int to = j+a[i].n;            if(to > D)    break;            LL now = k*a[i].p;            now += (LL)(D-to)/a[i].m * k*a[i].p;            if(now > a[i].q) {                LL get;                if(tot > ss[k])    get = ss[k];                else    get = tot;                ss[k] -= (int)get;                tot -= get;                cur -= get*a[i].q;                val[to] += get * k *a[i].p;                for(l = to+a[i].m;l <= D; l += a[i].m)    val[l] += get *k * a[i].p;            }            else    break;        }    }    if(cur > ans)    ans = cur;}int main() {    int t, w, h, A, i;    scanf("%d", &t);    while(t--) {        scanf("%d%d%d%d%d", &w, &h, &A, &D, &Y);        memset(s, 0, sizeof(s));        s[9] = (w/3) * (h/3);        s[(w%3)*3] += h/3;        s[(h%3)*3] += w/3;        if((w%3) * (h%3) == 1) {            s[5]++;    s[3] -= 2; s[1] += 2;        }        else if((w%3) * (h%3) == 4) {            s[8]++; s[6] -= 2; s[4] += 2;        }        else if((w%3)*(h%3) == 2) {            s[7]++; s[6]--; s[3]--; s[2] += 2;        }        else    s[(w%3)*(h%3)] ++;        for(i =0;i < A; i++)    scanf("%d%d%d%d", &a[i].q, &a[i].p, &a[i].n, &a[i].m);        ans = Y;        for(i = 0;i < A ; i++) {            if(a[i].m == 0)    solve1(i);            else    solve2(i);        }        printf("%I64d\n", ans);    }    return 0;}


原创粉丝点击