您的位置:首页 > 其它

uva 10465 - Homer Simpson(贪心)

2015-01-22 19:33 1501 查看
Homer SimpsonTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
SubmitStatus

Description



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


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<map>

#define N 100010
#define Mod 10000007
#define lson l,mid,idx<<1
#define rson mid+1,r,idx<<1|1
#define lc idx<<1
#define rc idx<<1|1
const double EPS = 1e-11;
const double PI = acos(-1.0);
typedef long long ll;

const int INF=1000010;

using namespace std;

int n,m,t;

int main()
{
    //freopen("test.in","r",stdin);
    while(cin>>m>>n>>t)
    {
        int ans2=t,ans=0,ans1=0;
        for(int i=0; i<=t/m; i++)
        {
            int x=(t-i*m)/n;
            if((i*m+x*n!=t))
            {
                if((t-i*m-x*n)<ans2)
                {
                    ans=i+x;
                    ans2=t-i*m-x*n;
                }
                else if((t-i*m-x*n)==ans2&&ans<i+x)
                ans=i+x;
            }
            if(ans1<(i+x)&&(i*m+x*n==t))
                ans1=i+x;
        }
        if(ans1)
        {
            printf("%d\n",ans1);
            continue;
        }
        printf("%d",ans);
        printf(" %d\n",ans2);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: