A - Marjar Cola

Marjar Cola is on sale now! In order to attract more customers, Edward, the boss of Marjar Company, decides to launch a promotion: If a customer returns x empty cola bottles or y cola bottle caps to the company, he can get a full bottle of Marjar Cola for free!

Now, Alice has a empty cola bottles and b cola bottle caps, and she wants to drink as many bottles of cola as possible. Do you know how many full bottles of Marjar Cola she can drink?
Note that a bottle of cola consists of one cola bottle and one bottle cap.

Input
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 100), indicating the number of test cases. For each test case:

The first and only line contains four integers x, y, a, b (1 ≤ x, y, a, b ≤ 100). Their meanings are described above.

Output
For each test case, print one line containing one integer, indicating the number of bottles of cola Alice can drink. If Alice can drink an infinite number of bottles of cola, print “INF” (without the quotes) instead.
Sample Input
2
1 3 1 1
4 3 6 4

Sample Output
INF
4

Hint
For the second test case, Alice has 6 empty bottles and 4 bottle caps in hand. She can return 4 bottles and 3 caps to the company to get 2 full bottles of cola. Then she will have 4 empty bottles and 3 caps in hand. She can return them to the company again and get another 2 full bottles of cola. This time she has 2 bottles and 2 caps in hand, but they are not enough to make the exchange. So the answer is 4.






题意:给你a、b和可乐瓶和可乐盖,你可以用x个可乐瓶或者y个可乐盖换一瓶可乐,问最多能换多少瓶可乐,(让我费解的是,为什么可以换INF。。。。)

思路:什么情况下可以换INF瓶可乐(我也要。。。。T_T)显然,当x = 1 or y = 1 和 x = 2 and y = 2 and a>=x or b>=y 时可以换INF,,,我试了超™久,卡在了这一组(2 2 2 1)样例,这个也是INF,,,我崩溃了,,还是自己太菜了,代码的鲁棒性不够强。。。枯了。。。。。。

//#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>			//stack的头文件
using namespace std ;
typedef long long ll;
#define MAXN 501
#define INF 0x3f3f3f3f
#define MALL (BiTnode *)malloc(sizeof(BiTnode));

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int x, y, a, b;
        scanf("%d %d %d %d", &x, &y, &a, &b);
        if(x == 1 || y == 1 || (x == 2 && y == 2 && (a>=x || b>=y)))
            cout << "INF" << '\n';
        else
        {
            int sum=0;
            while(a>=x || b>=y)
            {
                int cnt = a/x + b/y;
//                cout << a/x << ' ' << b/y << '\n';
                sum+=a/x;
                sum+=b/y;
                a = a%x + cnt;
                b = b%y + cnt;
//                cout << a <<' ' << b << '\n';
            }
            cout << sum << '\n';
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值