让我回想起了小学的时候,空瓶换饮料还能向别人借一个空瓶喝了再还回去的神奇问题……

开始时思考,特判一下a=1或者b=1的情况为INF就可以了,然后发现2 2 1 2这样的样例也是能够喝到无穷多瓶饮料的。

所以干脆直接做循环,每次循环模拟换了饮料然后喝掉的情形,如果发现喝完空瓶子不减少或者瓶盖子不减少,那显然是能喝不知道多少瓶饮料了,就直接输出INF。

 #include<cstdio>
int x,y,a,b,cnt;
bool flag;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&x,&y,&a,&b);//x空瓶 or y瓶盖换满瓶 ; 现有a空瓶,b瓶盖
cnt=;
flag=;
while(a>=x || b>=y)
{
int now_a=a,now_b=b;
if(a>=x)
{
int c=a/x;
a=a%x+c;
b+=c;
cnt+=c;
}
if(b>=y)
{
int c=b/y;
b=b%y+c;
a+=c;
cnt+=c;
}
if(a>=now_a && b>=now_b)
{
printf("INF\n");
flag=;
break;
}
}
if(flag) printf("%d\n",cnt);
}
}

ZOJ 3948 - Marjar Cola的更多相关文章

  1. ZOJ - 3948 Marjar Cola 【循环】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3948 题意 用 x 个 瓶身 可以 换 一瓶饮料 用 y 个 瓶 ...

  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 3860: - Find the Spy

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

  6. ZOJ 3819 Average Score(平均分)

    Description 题目描述 Bob is a freshman in Marjar University. He is clever and diligent. However, he is n ...

  7. ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA

    ZOJ Problem Set - 3946 Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the ...

  8. ZOJ 2819 Average Score 牡丹江现场赛A题 水题/签到题

    ZOJ 2819 Average Score Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge ...

  9. ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。

    Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...

随机推荐

  1. 【安全开发】java安全编码规范

    申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...

  2. Bypass D盾_IIS防火墙SQL注入防御(多姿势)

    0X01 前言 D盾_IIS防火墙,目前只支持Win2003服务器,前阵子看见官方博客说D盾新版将近期推出,相信功能会更强大,这边分享一下之前的SQL注入防御的测试情况.D盾_IIS防火墙注入防御策略 ...

  3. java中调用groovy

    Groovy在Java中的应用,做几个小例子以备查 package com.boco.efficiency.groovy; import groovy.lang.Binding; import gro ...

  4. Django SimpleCMDB WSGI

    一.WSGI 介绍 (1) 在前面的学习中,我们是通过 python manage.py runserver 0.0.0.0:8000 来启动并访问开发服务器的:(2) 但在实际中我们是通过直接访问 ...

  5. 使用 requests 访问 HTTPS

    当我们访问 HTTPS 的网站时,需要进行证书验证,在浏览器中可以自动处理验证问题,在 Python 中有以下两种做法: import requests //不进行证书验证,但这种方式会出现警告,如下 ...

  6. U3D之Editor扩展学习

    Unity3D提供了强大的编辑器扩展机制,在项目开发中,如果可以将一些繁琐的工作放在编辑器扩展中进行,则会大大提高效率.本文对编辑器扩展进行了一些总结,希望对有兴趣编写编辑器扩展的开发人员有所帮助.当 ...

  7. 如何构建日均千万PV Web站点 (一)

    其实大多数互联网网站起初的网站架构都是(Linux+Apache+MySQL+PHP). 不过随着时代的发展,科技的进步.互联网进入寻常百姓家的生活.所谓的用户的需求,铸就了一个个互联网大牛: htt ...

  8. Git的撤销与回滚

    1,commit 之前的撤销 未添加至暂存区的撤销(add 之前) git status git checkout . 已添加至暂存区的撤销(add 之后,有或者没有commit操作都可以执行) gi ...

  9. 【LeetCode OJ】Swap Nodes in Pairs

    题目:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2 ...

  10. numpy基本方法

    在学习python的时候常常需要numpy这个库,每次都是用一个查一个,这个,终于见到一个完整的总结了http://blog.csdn.net/blog_empire/article/details/ ...