题目链接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3948
题意 用 x 个 瓶身 可以 换 一瓶饮料 用 y 个 瓶盖 可以换 一瓶饮料
然后 换得一瓶饮料后 又可以得到 一个瓶盖 和 一个瓶身
然后 给出 刚开始 a 个 瓶身 和 b 个瓶盖 求最后 最多可以换得 多少饮料
如果 可以一直换下去 输出 INF
思路 我们只要 一轮一轮的 模拟换下去 然后 到达一个 阈值 就输出 INF 否则 输出 答案就可以了
AC代码
#include <string> #include <iostream> #include <cstdio> #include <cstring> #include <ctype.h> #include <cmath> #include <climits> #include <cstdlib> #include <algorithm> #include <deque> #include <queue> #include <vector> #include <map> #include <stack> #include <set> #include <numeric> #include <sstream> #include <iomanip> #include <limits> #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const int INF = 9999; int main() { int t; cin >> t; while (t--) { int x, y, a, b; scanf("%d%d%d%d", &x, &y, &a, &b); int ans = 0; int flag = 1; while (a >= x || b >= y) { int c = a / x; int d = b / y; a %= x; b %= y; a += c + d; b += c + d; ans += c + d; if (ans > INF) { flag = 0; break; } } if (flag) printf("%d\n", ans); else printf("INF\n"); } }转载于:https://www.cnblogs.com/Dup4/p/9433164.html
相关资源:JAVA上百实例源码以及开源项目