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 ...
随机推荐
- Python基础数据类型补充及深浅拷贝
本节主要内容:1. 基础数据类型补充2. set集合3. 深浅拷贝主要内容:一. 基础数据类型补充首先关于int和str在之前的学习中已经讲了80%以上了. 所以剩下的自己看一看就可以了.我们补充给一 ...
- HDU 6464 权值线段树 && HDU 6468 思维题
免费送气球 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 2874 Connections between cities(LCA)
题目链接 Connections between cities LCA的模板题啦. #include <bits/stdc++.h> using namespace std; #defin ...
- 作为使用者对qq拼音输入法和搜狗输入法的评价
我还记得在打字方面从一开始XP里面自带的中文输入法到QQ拼音输入法的过度,当时第一次使用qq拼音最大的感受就是这个输入法很智能,给人一种恍然一新的感觉,对于XP系统中自带的拼音输入法,QQ拼音最大的特 ...
- Smart3D系列教程8之 《模型合并——相邻地区多次建模结果合并》
迄今为止,Wish3D已经出品推出了7篇系列教程,从倾斜摄影的原理方法.采集照片的技巧.Smart3D各模块的功能应用.小物件的照片重建.大区域的地形重建到DSM及正射影像的处理生产,立足于建模软件的 ...
- spring security开发步骤
1.web.xml中加载spring ,spring security 2.spring security配置文件中配置好.... 3.自己写一个myFilter代替原有的FilterSecurity ...
- 前端学习——使用Ajax方式POST JSON数据包
0.前言 本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...
- Android相关工具下载(ADT、NDK等等)
一个非常牛掰的网站,可以下载很多Android相关的工具等 网址为: http://www.androiddevtools.cn/
- python(19)- 列表生成式和生成器表达式练习Ⅰ
列表表达式 程序一: 常规写法: egg_list=[] for i in range(100): egg_list.append('egg%s' %i) print(egg_list) 列表表达式写 ...
- Leetcode_num2_Maximum Depth of Binary Tree
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...