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");
}
}
ZOJ - 3948 Marjar Cola 【循环】的更多相关文章
- ZOJ 3948 - Marjar Cola
让我回想起了小学的时候,空瓶换饮料还能向别人借一个空瓶喝了再还回去的神奇问题…… 开始时思考,特判一下a=1或者b=1的情况为INF就可以了,然后发现2 2 1 2这样的样例也是能够喝到无穷多瓶饮料的 ...
- 2017浙江省赛 B - Problem Preparation ZOJ - 3959
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 题目: It's time to prepare the pr ...
- 2017 浙大校赛 [Cloned]
https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namesp ...
- 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 ...
- ZOJ - 3939 The Lucky Week(日期循环节+思维)
Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date. ...
- ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)
题目链接 ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...
- 重拾ZOJ 一周解题
ZOJ 2734 Exchange Cards 题目大意: 给定一个值N,以及一堆卡片,每种卡片有一个值value和数量number.求使用任意张卡片组成N的方式. 例如N = 10 ,cards(1 ...
- ZOJ 3626(树形DP+背包+边cost)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3626 题目大意:树中取点.每过一条边有一定cost,且最后要回 ...
- ZOJ 3860: - Find the Spy
3860 - Find the Spy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
随机推荐
- 2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02)
B Bricks 计算几何乱搞 题意: 给你个立方体,问你能不能放进一个管道里面. 题解: 这是一道非常迷的题,其问题在于,你可以不正着放下去,你需要斜着放.此时你需要枚举你旋转的角度,来判断是否可行 ...
- MySql----on duplicate key
mysql on duplicate key 语句是解决key 冲突的问题,同时 ,key 包括 primary key 和 unique key 等
- Android Service实现双向通信(一)
首先,大概来总结一下与Service的通信方式有很多种: 通过BroadCastReceiver:这种方式是最简单的,只能用来交换简单的数据: 通过Messager:这种方式是通过一个传递一个Mess ...
- DevExpress的GridControl如何实现打印和打印预览 z
第一种方法: System.Drawing.Printing.PageSettings set_print_page = new System.Drawing.Printing ...
- iOS- Exception Type: 00000020:什么是看门狗机制(转)
1.前言 前几天我们项目闪退之后遇到的一个Crash,之后逛了许多论坛,博客都没有找到满意的回复 在自己做了深入的研究之后,对iOS的看门狗机制有了一个基本的了解 而有很多奇怪的Crash可 ...
- Android -- native关键字
native关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中.Java语言本身不能对操作系统底层进行访问和操作,但是可以通过JNI接口 ...
- 【Tensorflow】tf.argmax函数
tf.argmax(input, axis=None, name=None, dimension=None) 此函数是对矩阵按行或列计算最大值 参数 input:输入Tensor axis:0表示 ...
- 手机遥控器,3.5mm耳机接口红外遥控改造解析
很多家电都用红外遥控,如电视机.机顶盒.空调.电风扇等.越来越多的遥控器反而给我们带来了更多的问题,有时找不到遥控器放哪儿了,或者混淆了都是麻烦,事实上对手机进行简单的改造,可以自制一个万能红外遥控器 ...
- 关于mysql engine(引擎)的疑问
http://bbs.chinaunix.net/thread-989698-1-1.html
- PJSIP 调用的GUID库
PJSIP库产生随机序列串用到GUID库,针对不同的平台使用的方式不同:Windows平台下使用的是Windows系统API CoCreateGuid,在方法 pj_generate_unique_s ...