题目链接

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");
}
}

ZOJ - 3948 Marjar Cola 【循环】的更多相关文章

  1. ZOJ 3948 - Marjar Cola

    让我回想起了小学的时候,空瓶换饮料还能向别人借一个空瓶喝了再还回去的神奇问题…… 开始时思考,特判一下a=1或者b=1的情况为INF就可以了,然后发现2 2 1 2这样的样例也是能够喝到无穷多瓶饮料的 ...

  2. 2017浙江省赛 B - Problem Preparation ZOJ - 3959

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 题目: It's time to prepare the pr ...

  3. 2017 浙大校赛 [Cloned]

    https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namesp ...

  4. The 17th Zhejiang University Programming Contest Sponsored by TuSimple A

    Marjar Cola Time Limit: 1 Second      Memory Limit: 65536 KB Marjar Cola is on sale now! In order to ...

  5. ZOJ - 3939 The Lucky Week(日期循环节+思维)

    Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date. ...

  6. ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)

    题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...

  7. 重拾ZOJ 一周解题

    ZOJ 2734 Exchange Cards 题目大意: 给定一个值N,以及一堆卡片,每种卡片有一个值value和数量number.求使用任意张卡片组成N的方式. 例如N = 10 ,cards(1 ...

  8. ZOJ 3626(树形DP+背包+边cost)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3626 题目大意:树中取点.每过一条边有一定cost,且最后要回 ...

  9. ZOJ 3860: - Find the Spy

    3860 - Find the Spy Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu S ...

随机推荐

  1. LeetCode OJ--Longest Consecutive Sequence ***

    http://oj.leetcode.com/problems/longest-consecutive-sequence/ 起初想的是排序,查了下O(n)的排序算法有计数排序.基数排序.桶排序.后来考 ...

  2. python学习之-- 故障记录汇总

    以下为我编程期间遇到的错误并进行记录,起始时间2017-6-21 时间:2018/11/21问题现象:ajax 执行异步提交后,在访问日志看出现了2次post执行分析:默认ajax提交是执行一次,然后 ...

  3. linux time

    uint32_t midtime; static struct timeval startstart,midmid; while (ros::ok()) { gettimeofday(&sta ...

  4. 第2章 Spring Boot 文档

    Spring Boot 文档 本节简要介绍了Spring Boot文档,是整个文档的参考指南. 您可以完整阅读本参考指南,或者如果您不感兴趣的话可以跳过该部分. 1. 关于文档 Spring Boot ...

  5. Html中的 http-equiv="X-UA-Compatible" 解释

    1.X-UA-Compatible X-UA-Compatible是自从IE8新加的一个设置,对于IE8以下的浏览器是不识别的. 通过在meta中设置X-UA-Compatible的值,可以指定网页的 ...

  6. BZOJ1005明明的烦恼 Prufer + 分解質因數 + 高精度

    @[高精度, Prufer, 質因數分解] Description 自从明明学了树的结构,就对奇怪的树产生了兴趣......给出标号为1到N的点,以及某些点最终的度数,允许在 任意两点间连线,可产生多 ...

  7. openssl转换各种证书的语法收集

    参考网址:https://www.sslshopper.com/ssl-converter.html 个人总结:先找准要生成什么证书先,尤其是正规购买的流程与openssl生成的不一样,所以先确定是什 ...

  8. MFC改变控件颜色

    from http://www.cppblog.com/FandyM/archive/2010/07/21/120972.aspx MFC应用程序中,要改变控件的背景色可通过重载OnCtlColor( ...

  9. Utuntu 和 window共享文件

    由于自己想用服务器跑代码,数据集和模型一般都在本机电脑上,用实验室服务器需要拷贝数据或者,在服务器上重新下载数据很麻烦 都在局域网内可以实现文件共享,代码和数据都在本地,共享给服务器,只需要使用服务器 ...

  10. SolidEdge 工程图中如何标注尺寸公差

    1 先标注基准框,输入基准符号(A B C之类的)   2 点击特征控制,设置马上要标注的特征和公差(可以保存为模板)   3 直接点击要标注的元素即可   4 没有基准的形位公差标注也一样