A
来源:互联网 发布:蓝月传奇10转生数据 编辑:程序博客网 时间:2024/06/07 17:57
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.
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.
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.
21 3 1 14 3 6 4
INF4
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.
判断他是不是重复,就可以解决INF,判断可不可以兑换,就可以输出答案。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int f[1005][1005];int x,y,z,t;int main(){ int n; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d%d%d%d",&x,&y,&z,&t); memset(f,0,sizeof(f)); int ans =0; while(true) { f[z][t] = 1; if(z>=x) { int o = z/x; z-=x*o; z+=o; t+=o; ans+=o; // cout<<t<<z<<endl; } if(t>=y) { int o = t/y; t-=o*y; z+=o; t+=o; ans+=o; // cout<<t<<z<<endl; } if(z<x && t<y) { printf("%d\n",ans); break; } if(f[z][t] || x==1 || y==1) { printf("INF\n"); break; } } } return 0;}
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- A
- A*
- a
- A
- a
- MySQL基础总结
- 国内各种坐标系以及对应的转化方法
- Linux---VMware 虚拟机安装 CentOS 7.3、配置JDK环境、Tomcat服务器、MySQL数据库
- HTTP详解(十四):非对称加密算法正传
- $.each jquery遍历 demo
- A
- Intellij IDEA Scala开发环境搭建
- ubuntu命令
- hdu 2072-单词数(字典树)
- [torch]nngraph parameters of the node
- 通过反射取得hashmap的值
- icp前端问题
- stoner pipeline simular v9.5(SPS)输气管道仿真软件_USB硬件加密锁运行稳定\
- mysql分库分表