uva 10465 - Homer Simpson(贪心)

来源:互联网 发布:阿里云可用区什么意思 编辑:程序博客网 时间:2024/06/01 08:21
Homer SimpsonTime Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu
SubmitStatus

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 integersm, 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 543 5 55

Sample Output

1817


#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|1const 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;}


0 0
原创粉丝点击