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 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的更多相关文章
- 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 ...
 - 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 题解: 题意 ...
 - 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 ...
 - The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)
		
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A Thanks, TuSimple! Time ...
 - 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 ...
 - 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表示 ...
 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack
		
题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...
 - 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 ...
 - 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 ...
 
随机推荐
- busybox 终端支持 ctrl-r
			
Busybox Settings ---> Busybox Library Tuning ---> [*] History saving [ ] Save history on shell ...
 - libusb 源码阅读
			
libusb_init(NULL), 如果传入一个NULL, 则libusb 内部会有一个 usbi_default_context 变量在内部保存上下文. 这样以后调用 libusb 函数时可以不指 ...
 - Python开发【第3节】【Python分支结构与循环结构】
			
1.流程控制 流程: 计算机执行代码的顺序就是流程 流程控制: 对计算机代码执行顺序的管理就是流程控制 流程分类: 流程控制共分为3类: 顺序结构 分支结构/选择结构 循环结构 2.分支结构(if. ...
 - NPOI实现Excel导入
			
导入功能实现: ]; GetExtensionsFromFileStream(file.InputStream); using NPOI.XSSF.UserModel; public List< ...
 - leetcode笔记:Pascal's Triangle
			
一. 题目描写叙述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
 - Robots协议应用与写法研究
 - Tomcat的虚拟主机的配置
			
比如:配置一个虚拟主机的名字是www.sina.com 1 改动window系统中的HOST文件[C:\WINDOWS\system32\drivers\etc\hosts] 127.0.0.1 ...
 - 基于Ubuntu 14.04 LTS编译Android4.4.2源码
			
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/gobitan/article/details/24367439 基于Ubuntu 14.04 LTS ...
 - UIBarButtonSystemItem 各种款式
 - gson如何转化json数组
			
String.JsonObject.JavaBean 互相转换 User user = new Gson().fromJson(jsonObject, User.class); User user = ...