10465 - Homer Simpson
Time limit: 3.000 seconds
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 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
Problem setter: Sadrul Habib Chowdhury
Solution author: Monirul Hasan (Tomal)
Time goes, you say? Ah no!
Alas, Time stays, we go.
-- Austin Dobson
题意是一个人要在时间t内吃汉堡,有两种汉堡,需要的时间分别为m和n,问你最多能吃多少个,如果其中有间隔输出间隔时间。
思路:只有两件物品的完全背包。
/*
ID: xinming2
PROG: stall4
LANG: C++
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cassert>
using namespace std;
///#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define mk make_pair
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
const int MAXN = 10000 + 50;
const int sigma_size = 26;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
#define eps 1e-8
const int mod = (int)1e9 + 7;
typedef long long LL;
const LL MOD = 1000000007LL;
const double PI = acos(-1.0);
typedef pair<int , int> pi;
#define Bug(s) cout << "s = " << s << endl;
///#pragma comment(linker, "/STACK:102400000,102400000")
int n , m , t;
int dp[MAXN];
int main()
{
while(~scanf("%d%d%d" , &m , &n, &t ))
{
clr(dp , -1);
dp[0] = 0;
for(int i = m ; i <= t ; i++)
{
if(dp[i - m] != -1)dp[i] = max(dp[i] , dp[i - m] + 1);
}
for(int i = n ; i <= t ; i++)
{
if(dp[i - n] != -1)dp[i] = max(dp[i] , dp[i - n] + 1);
}
if(dp[t] != -1)printf("%d\n" , dp[t]);
else
{
for(int i = t ; i >= 0 ; i--)
{
if(dp[i] != -1)
{
printf("%d %d\n" , dp[i], t - i);
break;
}
}
}
}
return 0;
}