10465 - Homer Simpson 贪心
| 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\n",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("\n");
}
return 0;
}
10465 - Homer Simpson 贪心的更多相关文章
- UVa 10465 Homer Simpson (枚举)
10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- UVA 10465 Homer Simpson(全然背包: 二维目标条件)
UVA 10465 Homer Simpson(全然背包: 二维目标条件) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&a ...
- UVA 10465 Homer Simpson(dp + 完全背包)
Problem C: Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Homer Simpson, a very smart guy, ...
- UVa 10465 Homer Simpson(DP 全然背包)
题意 霍默辛普森吃汉堡 有两种汉堡 一中吃一个须要m分钟 还有一种吃一个须要n分钟 他共同拥有t分钟时间 要我们输出他在尽量用掉全部时间的前提下最多能吃多少个汉堡 假设时间无法用 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 算法入门经典大赛 Dynamic Programming
111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...
- 利用奇异值分解(SVD)简化数据
特征值与特征向量 下面这部分内容摘自:强大的矩阵奇异值分解(SVD)及其应用 特征值分解和奇异值分解在机器学习领域都是属于满地可见的方法.两者有着很紧密的关系,在接下来会谈到,特征值分解和奇异值分解的 ...
- [转载]javascript创建对象的几种方式
原文链接:http://qingfeng825.iteye.com/blog/1935648 1. 工厂方法:能创建并返回特定类型对象的工厂函数(factory function). function ...
- Code Complete阅读笔记(三)
2015-05-26 628 Code-Tuning Techniques ——Even though a particular technique generally represen ...
随机推荐
- [Quick-x]移动CCEditbox的父对象导致输入框位置偏移问题
CCEditbox对象添加到某个layer,当layer移动时候,editbox输入状态下输入光标保持在原位,看起来就是光标发生了偏移 如果开始时添加的editbox不在屏幕内的话,光标会出现在屏幕边 ...
- 正确使用c语言中的头文件
我们在使用c编程的时候经常会遇到头文件,前段时间我自己做了个小项目的时候,也遇到了关于头文件的问题. 预处理器发现#include 指令后,就会寻找后跟的文件名并把这个文件包含的内容包含到当前文件中. ...
- 被IDEA的打包功能打败了:dubbo服务端打包注意事项
下午在搭建一个基于dubbo和spring的服务端项目.结果打包成jar后各种报错. 起初是因为idea的机制,导致META-INF下自己的Mainfest.mf总是莫名被覆盖,于是报找不到主函数.后 ...
- 【HDOJ】1042 N!
肯定是大叔,本来以为用加法做乘法,后来想想这样麻烦,还是可以使用乘法的,按位乘,ov可以看成不止一位,程序如下所示: #include <stdio.h> #define MAX 4000 ...
- poj1947Rebuilding Roads(树形DP)
链接 刚接触 树上背包..有点抽象化 找好父亲和儿子的关系 及状态转移方程 代码里有详细的注释 就不解释了 #include <iostream> #include<cstdio& ...
- a++与=++a的区别
//a++;//a=a+1; // ++a;//a=a+1; //Console.WriteLine(a++);// Console.WriteL ...
- log4net面面观之Repository
转:http://itrust.cnblogs.com/archive/2006/07/17/452895.html 上回说道:Repository可以说成基于一个log4net配置节创建的log4n ...
- HDU 1695 GCD 莫比乌斯反演
分析:简单的莫比乌斯反演 f[i]为k=i时的答案数 然后就很简单了 #include<iostream> #include<algorithm> #include<se ...
- bzoj 1030 [JSOI2007]文本生成器(AC自动机+DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1030 [题意] 给n个小串,随机构造一个长为m的大串,一个串合法当且仅当包含一个或多个 ...
- 使用ssh协议挂载远程文件目录
安装sshfs 命令:sudo apt-get install sshfs 使用modprobe加载模块 命令:sudo modprobe fuse 设置权限 把下面的<username> ...
