Ultraviolet A 10465 Homer Simpson (greedy, the maximum number of hamburgers eaten in a given period of time)

Source: Internet
Author: User

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
   
    



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.