zoukankan      html  css  js  c++  java
  • UVa 10465 Homer Simpson 背包

    Return of the Aztecs

    Problem C: Homer Simpson

    Time Limit: 3 seconds
    Memory Limit: 32 MB

    Homer Simpson, a very smart guy, likes eating Krusty-burgers. It takes Homer m minutes to eat a Krusty- burger. However, there�s a new type of burger in Apu�s Kwik-e-Mart. Homer likes those too. It takes him n minutes to eat one of these burgers. Given t minutes, you have to find out the maximum number of burgers Homer can eat without wasting any time. If he must waste time, he can have beer.

    Input

    Input consists of several test cases. Each test case consists of three integers m, n, t (0 < m,n,t < 10000). Input is terminated by EOF.

    Output

    For each test case, print in a single line the maximum number of burgers Homer can eat without having beer. If homer must have beer, then also print the time he gets for drinking, separated by a single space. It is preferable that Homer drinks as little beer as possible.

    Sample Input

    3 5 54
    3 5 55
    

    Sample Output

    18
    17
    

    Problem setter: Sadrul Habib Chowdhury
    Solution author: Monirul Hasan (Tomal)

    Time goes, you say? Ah no!
    Alas, Time stays, we go.
    -- Austin Dobson


    ---------

    啊好水好水

    ---------

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    int n,m,t;
    int f[11111];
    
    int main()
    {
        while (~scanf("%d%d%d",&n,&m,&t))
        {
            memset(f,-1,sizeof(f));
            f[0]=0;
            for (int i=0;i<=t-n;i++)
            {
                if (f[i]>=0)
                {
                    f[i+n]=max( f[i+n],f[i]+1 );
                }
            }
            for (int i=0;i<=t-m;i++)
            {
                if (f[i]>=0)
                {
                    f[i+m]=max( f[i+m],f[i]+1 );
                }
            }
            if (f[t]!=-1)
            {
                printf("%d\n",f[t]);
            }
            else
            {
                int ans=0;
                int tmp=0;
                for (int i=t;i>=0;i--)
                {
                    if (f[i]!=-1)
                    {
                        ans=f[i];
                        tmp=i;
                        break;
                    }
                }
                printf("%d %d\n",ans,t-tmp);
            }
        }
        return 0;
    }
    




  • 相关阅读:
    集合的代数运算
    集合的代数运算
    poj1639 Picnic Planning,K度限制生成树
    C/C++学习站点资源
    Mustache 使用心得总结
    PostgreSQL服务端监听设置及client连接方法
    【线性规划与网络流24题】汽车加油行驶问题 分层图
    linux系统下信号具体解释2
    【数据结构】栈-数组的实现
    EJB究竟是什么,真的那么神奇吗??
  • 原文地址:https://www.cnblogs.com/cyendra/p/3226331.html
Copyright © 2011-2022 走看看