Marjar Cola


Time Limit: 1 Second      Memory Limit: 65536 KB

Marjar Cola is on sale now! In order to attract more customers, Edward, the boss of Marjar Company, decides to launch a promotion: If a customer returns x empty cola bottles or y cola bottle caps to the company, he can get a full bottle of Marjar Cola for free!

Now, Alice has a empty cola bottles and b cola bottle caps, and she wants to drink as many bottles of cola as possible. Do you know how many full bottles of Marjar Cola she can drink?

Note that a bottle of cola consists of one cola bottle and one bottle cap.

Input

There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 100), indicating the number of test cases. For each test case:

The first and only line contains four integers x, y, a, b (1 ≤ x, y, a, b ≤ 100). Their meanings are described above.

Output

For each test case, print one line containing one integer, indicating the number of bottles of cola Alice can drink. If Alice can drink an infinite number of bottles of cola, print "INF" (without the quotes) instead.

Sample Input

2
1 3 1 1
4 3 6 4

Sample Output

INF
4

Hint

For the second test case, Alice has 6 empty bottles and 4 bottle caps in hand. She can return 4 bottles and 3 caps to the company to get 2 full bottles of cola. Then she will have 4 empty bottles and 3 caps in hand. She can return them to the company again and get another 2 full bottles of cola. This time she has 2 bottles and 2 caps in hand, but they are not enough to make the exchange. So the answer is 4.

题意:换一瓶饮料需要a或者b种材料,现在我有x,y个材料,问最多换几个,如果是无限就输出INF

解法:模拟,设置一个上限,如果超过就输出INF

 #include<bits/stdc++.h>
using namespace std;
long long t;
long long a,b,c,d;
int main()
{
while(cin>>t)
{
while(t--)
{
cin>>a>>b>>c>>d;
long long an,bn;
long long sum=;
long long x=;
an=c;
bn=d;
long long y=;
while(an>=a||bn>=b)
{
// cout<<an<<" "<<bn<<endl;
sum+=(an/a+bn/b);
long long an1=(an/a+bn/b)+an%a;
long long bn1=(an/a+bn/b)+bn%b;
if(an1>=an&&bn1>=bn)
{
x=;
break;
}
else
{
an=an1;
bn=bn1;
}
y++;
if(y>=)
{
x=;
break;
}
}
if(x)
{
cout<<"INF"<<endl;
}
else
{
cout<<sum<<endl;
}
}
}
return ;
}

The 17th Zhejiang University Programming Contest Sponsored by TuSimple A的更多相关文章

  1. The 17th Zhejiang University Programming Contest Sponsored by TuSimple J

    Knuth-Morris-Pratt Algorithm Time Limit: 1 Second      Memory Limit: 65536 KB In computer science, t ...

  2. zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)

    题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...

  3. The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)

    传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorizati ...

  4. The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A     Thanks, TuSimple! Time ...

  5. Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice ...

  6. 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...

  7. The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack

    题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...

  8. The 18th Zhejiang University Programming Contest Sponsored by TuSimple

    Pretty Matrix Time Limit: 1 Second      Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...

  9. ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...

随机推荐

  1. 软件版本号(BETA、RC、ALPHA、Release、GA等)

    Alpha:        Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用.是希腊字母的第一位,表示最初级的版本,alpha 就是α,beta 就是β , ...

  2. 2017ACM/ICPC广西邀请赛 K- Query on A Tree trie树合并

    Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Othe ...

  3. oracle的索引有几种?各有何用途?

    1. b-tree索引Oracle数据库中最常见的索引类型是b-tree索引,也就是B-树索引,以其同名的计算科学结构命名.CREATE INDEX语句时,默认就是在创建b-tree索引.没有特别规定 ...

  4. Hibernate commit() 和flush() 的区别

    <<精通Hibernate java对象持久化技术详解>> ,flush()方法进行清理缓存的操作,执行一系列的SQL语句,但不会提交事务;commit()方法会先调用flus ...

  5. Safair css hack

    一下方式不会影响chrome浏览器样式 _::-webkit-full-page-media, _:future, :root .class{ /*此处放css样式*/ }

  6. oracle性能监控

    https://blog.csdn.net/yangshangwei/article/details/52449489#监控事例的等待 https://blog.csdn.net/yangshangw ...

  7. Intelij Idea 2016.3.4激活

    https://www.haxotron.com/jetbrains-intellij-idea-crack-123/ http://idea.lanyus.com/

  8. HDU 1081:To The Max

    To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  9. linux初级学习笔记四:Linux文件管理类命令详解!(视频序号:03_1)

    本节学习的命令:cat(tac),more,less,head,tail,cut,sort,uniq,wc,tr 本节学习的技能:目录管理 文件管理 日期时间 查看文本 分屏显示 文本处理 文件管理命 ...

  10. 实现自定义xib和storyboard的加载,

    一:加载xib 1.分别创建xib,.h  .m文件继承自UIView. 在xib上绑定类名. 或者创建文件的时候直接勾选xib 2.在控制器中调用类方法 jyq52787网盘/ios/潭州学院/iO ...