ZOJ - 3948 Marjar Cola 【循环】

题目链接

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3948

题意
用 x 个 瓶身 可以 换 一瓶饮料 用 y 个 瓶盖 可以换 一瓶饮料

然后 换得一瓶饮料后 又可以得到 一个瓶盖 和 一个瓶身

然后 给出 刚开始 a 个 瓶身 和 b 个瓶盖 求最后 最多可以换得 多少饮料

如果 可以一直换下去 输出 INF

思路
我们只要 一轮一轮的 模拟换下去 然后 到达一个 阈值 就输出 INF 否则 输出 答案就可以了

AC代码

#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <deque>
#include <queue>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>

#define pb push_back

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int INF = 9999;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int x, y, a, b;
        scanf("%d%d%d%d", &x, &y, &a, &b);
        int ans = 0;
        int flag = 1;
        while (a >= x || b >= y)
        {
            int c = a / x;
            int d = b / y;
            a %= x;
            b %= y;
            a += c + d;
            b += c + d;
            ans += c + d;
            if (ans > INF)
            {
                flag = 0;
                break;
            }
        }
        if (flag)
            printf("%d\n", ans);
        else
            printf("INF\n");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值