Ultraviolet A 10465 Homer Simpson (greedy, the maximum number of hamburgers eaten in a given period of time)
Homer Simpson
Time Limit:3000 MS
Memory Limit:0 KB
64bit IO Format:% Lld & % llu
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 integersM, n, t (0 <m, n, t <10000). Input is terminated by EOF. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPGgzPk91dHB1dDwvaDM + fuse + U2FtcGxlIElucHV0PC9oMz4KPHByZSBjbGFzcz0 = "brush: java;"> 3 5 543 5 55Sample Output
1817
Problem setter: Sadrul Habib Chowdhury
Solution author: Monirul Hasan (Tomal)
Time goes, you say? Ah no!
Alas, Time stays, we go.
-- Austin Dobson
Question:
The maximum number of hamburgers consumed when the output does not waste time; otherwise, the maximum number and minimum waste time of the output hamburger are consumed when the minimum waste time is reached.
Solution:
Greedy, it takes a small amount of time to first point, then gradually reduce the number of this hamburger, increase the number of another hamburger.
#include
#include
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