zoukankan      html  css  js  c++  java
  • 10465

                                            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
    题意:尽量用完时间t,求出最多吃多少个汉堡;如果实在用不完,再输出和啤酒的时间。
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	int m,n,t,max,i;
    	while(~scanf("%d%d%d",&m,&n,&t))
    	{
    		if(m>n) /*保证m>n*/
    		{int temp=m;m=n;n=temp;}
    		max=t/m; /*最多的数量*/
    		int beer_time=t-max*m; /*喝啤酒的时间*/
    		if(beer_time==0)
    		{
    			printf("%d
    ",max);
    			continue;
    		}
    		for(i=1;i<=t/n;i++) 
    		{
    			int temp_max=(t-n*i)/m+i;
    			int temp_beer_time=t-((temp_max-i)*m+i*n);
                if(temp_beer_time>=0&&temp_beer_time<beer_time)
    			{
    				max=temp_max;
    				beer_time=temp_beer_time;
    			}
    			if(temp_beer_time==0)
    				break;
    		}
    		printf("%d",max);
    		if(beer_time!=0)
    			printf(" %d",beer_time);
    		printf("
    ");
    	}
    	return 0;
    }
  • 相关阅读:
    SSM实现mysql数据库账号密码加密连接
    获取系统相关信息 (CPU使用率 内存使用率 系统磁盘大小)
    JavaWeb(一) / /* /**的区别
    IDEA(一) 使用IDEA搭建SSM框架项目
    Mysql连接数据库异常汇总【必收藏】
    Java代理模式及动态代理详解
    SpringBoot集成Thymeleaf
    设计师,程序员,当心字体侵权
    Java开发神器Lombok使用详解
    日期格式化跨年bug,是否与你不期而遇?
  • 原文地址:https://www.cnblogs.com/aukle/p/3235423.html
Copyright © 2011-2022 走看看