zoj 3948 Marjar Cola
来源:互联网 发布:淘宝开店上传宝贝 编辑:程序博客网 时间:2024/06/03 05:08
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
21 3 1 14 3 6 4
Sample Output
INF4
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就可以无限换了。
但是还有一种情况,就如果换的瓶盖和瓶身都是2的情况,并且已有的瓶盖和瓶身之中有一个大于等于2,那也是可以无限换的。
其他情况都是有限个,模拟即可。
#include<map>#include<set>#include<cmath>#include<stack>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iomanip>#include<iostream>#include<algorithm>using namespace std;int main(){int t;cin>>t;while(t--){ int x,y,a,b; cin>>x>>y>>a>>b; if(x==1||y==1) cout<<"INF"<<endl; else if(x==2&&y==2&&a/x+b/y>=1) { cout<<"INF"<<endl; } else { long long int ans=0; while(a/x>=1||b/y>=1) { int aa=a/x; int bb=b/y; ans+=aa+bb; a=a-aa*x+aa+bb; b=b-bb*y+aa+bb; }cout<<ans<<endl; }}return 0;}
- ZOJ 3948 Marjar Cola
- zoj 3948 Marjar Cola
- Zoj 3984 Marjar Cola ( 暴力
- Marjar Cola
- zoj3948——Marjar Cola
- ACM刷题之ZOJ————Marjar Cola
- zoj 3568 Exchange for Cola
- 【ZOJ3948 The 17th Zhejiang University Programming Contest A】【暴力 or 讨论】Marjar Cola 瓶盖饮料换可乐
- ZOJ 3676 Edward's Cola Plan
- zoj-3676 Edward's Cola Plan 二分
- Cola
- 11150 - Cola
- Double Cola
- Cola HDU1495
- Applications Marjar University 积分统计
- SOJ-3601(Cola)
- UVa 11150 - Cola
- 1003 Exchange for Cola
- eclipse项目中的.settings .project .classpath 个人见解
- 用C代码写贪吃蛇游戏--创建一条蛇并移动
- CSplitterWnd去掉内部View滚动条的方法
- Vue bootstrap的简单结合应用
- 关于vector<>的一些使用记录
- zoj 3948 Marjar Cola
- Hibernate配置文件(Hibernate.cfg.xml)
- StringBuffer的用法
- bzoj 3060: [Poi2012]Tour de Byteotia 并查集
- MySql backup scripts--Mysql备份脚本
- MySQL-01-linux安装MySQL的两种方式及其遇到的问题
- 一些编程上的小经验
- Android Scroll详解(一):基础知识
- Jsonlib JsonObject.formObject().toString Integer为null 最后结果是0,String 为null ,最后结果是""(空字符串)