POJ 1042(贪心)

wa

#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
using namespace std;

const int INF = 0x3f3f3f3f;

struct node
{
    int fish;
    int decrease;
    int ID;
    int time;
}lake[30];

int route[30];

bool cmp1(node a, node b)
{
    if (a.fish == b.fish)
        return a.ID < b.ID;
    return a.fish > b.fish;
}
bool cmp2(node a, node b)
{
    return a.ID < b.ID;
}
int vs_main()
{
    int n;
    while (cin >> n, n)
    {
        int h;
        cin >> h;
        int Sum = h*12;//有多少个5分钟;
        memset(lake, 0, sizeof(lake));
        for (int i = 1; i <= n; i++)
        {
            cin >> lake[i].fish;
            lake[i].ID = i;
        }
        for (int i = 1; i <= n; i++)
        {
            cin >> lake[i].decrease;
        }
        for (int i = 1; i <= n - 1; i++)
        {
            cin >> route[i];
            Sum -= route[i];
        }
        int Count = 0;
        int temp = 0;
        while (Sum >=1)
        {
            sort(lake + 1, lake + n + 1, cmp1);
            Count += lake[1].fish;
            lake[1].fish -= lake[1].decrease;
            if (lake[1].fish < 0)
                lake[1].fish = 0;   
            if (lake[1].ID == temp)
            {
                Sum -= 2;
                lake[1].time +=10;
            }
            else
            {
                Sum -= 1;
                lake[1].time += 5;
            }
            temp = lake[1].ID;
        }
        sort(lake + 1, lake + n + 1, cmp2);
        for (int i = 1;i<= n-1; i++)
        {
            printf("%d, ", lake[i].time);
        }
        printf("%d\n", lake[n].time);
        printf("Number of fish expected: %d\n\n", Count);
    }
    return 0;
}

int main()
{
    int start = clock();
    freopen("in.txt", "r", stdin);
    //freopen("out.txt","w",stdout);
    printf("#===================#\n");
    vs_main();
    printf("#===================#\n");
    printf("Time:%.3lf\n", double(clock() - start) / CLOCKS_PER_SEC);
    //system("pause");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值