首页 > 其他 > 详细

uva 10465 - Homer Simpson

时间:2014-01-31 14:43:19      阅读:393      评论:0      收藏:0      [点我收藏+]

Return of the Aztecs

Problem C: Homer Simpson

Time Limit: 3 seconds
Memory Limit: 32 MB

bubuko.com,布布扣 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




题目大意:有个人喜欢吃汉堡,一种汉堡需要m分钟,另一种汉堡需要n分钟,给你 t 分钟,不浪费任何时间,问你最多吃几个汉堡?如果必须浪费时间,最少的剩余时间,最多的汉堡。

解决方法:用暴力算法既可以解决,只需要枚举汉堡的个数就OK


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int m,n,t;
    while(cin>>m>>n>>t){
        if(m<n) swap(m,n);
        int ans=0,l=t;
        for(int i=0;i<=t/m;i++){
            int tmp=(t-i*m)%n;
            if(tmp<l){
                l=tmp;
                ans=i;
            }
        }
        if(l>0) cout<<ans+(t-ans*m)/n<<" "<<l<<endl;
        else cout<<ans+(t-ans*m)/n<<endl;
    }
    return 0;
}



uva 10465 - Homer Simpson

原文:http://blog.csdn.net/a1061747415/article/details/18883009

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!