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 ...
随机推荐
- new[]上面居然有一个内存计数,怪不得delete[]从来不出错
开眼界了,留个爪,以后再仔细看几遍: http://www.cnblogs.com/hazir/p/new_and_delete.html
- Linux下删除大量文件
主要参考了http://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux 首先建立50万个文件 ➜ test ...
- A9.linux驱动
--- ---- ---
- jni.h头文件详解二
作者:左少华 博客:http://blog.csdn.net/shaohuazuo/article/details/42932813 转载请注明出处:http://blog.csdn.net/shao ...
- 存储过程系列之存储过程sql查询存储过程的使用
1.查询某个表被哪些存储过程(以下简称 SP)使用到 : select distinct object_name(id) from syscomments where id in (select ob ...
- C# 线程更新UI
最方便的用法: private void ViewMsg(string msg) { /* control.Invoke(new SetControlTextDelegate((ct, ...
- Oracle将英文字符集数据转换成中文
转换背景:老系统数据为英文字符集,需要将老数据(Oracle 8i)转换到oracle 10g(中文字符集)中 思路:先将老数据从8i的数据库中导出,导出的数据库文件为英文字符集,再将10g的数据库改 ...
- nmon for linux
nmon(为Nigel's performance Monitor的简写) for linux工具是 IBM开源的在POWER, x86, x86_64, Mainframe & now AR ...
- 多组 RadioButtonList 获取值
<div class="row"> <table> <thead><tr><th>操作</th ...
- opencv源代码
源代码都在modules文件夹下.搜索一个函数比如dft,在win7下 找到了
