zoukankan      html  css  js  c++  java
  • UVa 10465 Homer Simpson(DP 全然背包)

    

    题意 霍默辛普森吃汉堡  有两种汉堡  一中吃一个须要m分钟  还有一种吃一个须要n分钟  他共同拥有t分钟时间    要我们输出他在尽量用掉全部时间的前提下最多能吃多少个汉堡  假设时间无法用完  输出他吃的汉堡数和剩余喝酒的时间

    非常明显的全然背包问题  求两次  一次对个数  一次对时间即可了   时间用不完的情况下就输出时间的

    d1为个数的  d2为时间的  dt保存时间


    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define maxn 10005
    using namespace std;
    int w[2],t,d1[maxn],d2[maxn],dt[maxn];
    int main()
    {
        while (scanf("%d%d%d",&w[0],&w[1],&t)!=EOF)
        {
            memset(d1,0x8f,sizeof(d1));
            memset(dt,0,sizeof(dt));
            memset(d2,0,sizeof(d2));
            d1[0]=0;
            for(int i=0; i<2; ++i)
                for(int j=w[i]; j<=t; ++j)
                {
                    d1[j]=max(d1[j],d1[j-w[i]]+1);
                    if((dt[j]<dt[j-w[i]]+w[i])||((dt[j]==dt[j-w[i]]+w[i])&&(d2[j]<d2[j-w[i]]+1)))
                    {
                        dt[j]=dt[j-w[i]]+w[i];
                        d2[j]=d2[j-w[i]]+1;
                    }
                }
            if(dt[t]==t)
                printf("%d
    ",d1[t]);
            else
                printf("%d %d
    ",d2[t],t-dt[t]);
        }
        return 0;
    }
    
    

    Homer Simpson
     

    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



  • 相关阅读:
    Android SDK更新 Connection to http://dlssl.google.com refused 解决方法
    rsync服务架设(数据同步|文件增量备份)
    cocos2dx 环境搭建
    GMT、UTC、PDT 时间是什么?Linux下如何调整时区
    测试日志
    处理Oracle中杀不掉的锁
    熟悉常用的Linux操作
    综合练习:英文词频统计
    编译原理
    字符串、组合数据类型练习
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7103214.html
Copyright © 2011-2022 走看看