UVA 10465 Homer Simpson(贪心,在给定时间内吃的最多的汉堡数目)

 Homer Simpson
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF

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>

using namespace std;

int main(){
    int m,n,t,x1,y1,temp;
    while(scanf("%d%d%d",&m,&n,&t)!=EOF){
        int flag=0,mint=10000;
        if(m>n){
            temp=m;m=n;n=temp;
        }
        int x=t/m,y=0;
        for(;x>=0;){
            if(t==m*x+n*y){
                printf("%d\n",x+y);flag=1;break;
            }
            else if((t-m*x-n*y)%n!=0&&(t-m*x-n*y)/n==0){
                if(t-m*x-n*y<mint){
                    mint=t-m*x-n*y;
                    x1=x;y1=y;
                }
                x--;
            }
            else y++;
        }
        if(flag==0) printf("%d %d\n",x1+y1,mint);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值