Marjar Cola
来源:互联网 发布:苹果mac自有办公软件 编辑:程序博客网 时间:2024/05/20 12:24
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
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.
思路:有两种情况为无限 1.当瓶盖或空瓶数为1且持有的瓶盖数或空瓶数大于1, 2. 当瓶盖和空瓶数为2且持有的瓶盖数或空瓶数大于2时。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ int n,m,n1,m1,t; scanf("%d",&t); while(t--) { int sum=0; scanf("%d %d %d %d",&n,&m,&n1,&m1); if((n==1||m==1)&&(n1>=1||m1>=1)||(n==2&&m==2)&&(n1>=2||m1>=2)) { printf("INF\n"); } else { while(1) { if(n<=n1) { n1-=n; n1++; m1++; sum++; } if(m<=m1) { m1-=m; n1++; m1++; sum++; } if(n>n1&&m>m1) break; } printf("%d\n",sum); } } return 0;}
阅读全文
0 0
- Marjar Cola
- ZOJ 3948 Marjar Cola
- zoj 3948 Marjar Cola
- zoj3948——Marjar Cola
- Zoj 3984 Marjar Cola ( 暴力
- ACM刷题之ZOJ————Marjar Cola
- 【ZOJ3948 The 17th Zhejiang University Programming Contest A】【暴力 or 讨论】Marjar Cola 瓶盖饮料换可乐
- Cola
- 11150 - Cola
- Double Cola
- Cola HDU1495
- Applications Marjar University 积分统计
- SOJ-3601(Cola)
- UVa 11150 - Cola
- 1003 Exchange for Cola
- A. Double Cola
- A. Double Cola
- ZOJ_3568_Exchange for Cola(水题)
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 将数据库中的数据导入Solr索引库
- (十五)PathMeasure
- CT图之cnn
- [PHP]PhpStorm搭建PHP环境及PHP.ini丢失问题
- Marjar Cola
- Java键盘事件
- [USACO3.3]商店购物 Shopping Offers
- 实现多系统网络yum服务器和客户端配置
- JavaScript的字符串定义及实例
- PHP做中文分词技术
- NOIP2015 运输计划 树上差分(路径覆盖)
- 泛型
- 六度分离 HDU