ZOJ 3948 Marjar Cola
2017-04-12 11:12
363 查看
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.
x 个空可乐瓶或 y 个瓶盖可以换一瓶可乐(一瓶可乐包括一个可乐瓶以及一个瓶盖),已知有 a 个空瓶和 b 个瓶盖,问最多能换到多少瓶可乐?
无限兑换的情况仅有 x=1 或 y=1 以及 x=y=2 & (a>=2 || b>=2) 。
解法 2: 鉴于上述无限兑换的情况可能容易想漏,故直接模拟也可以。由于 x, y, a, b 都较小,所以选择一个阈值作为上限,到达某个阈值即可视为他在无限兑换。
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.
x 个空可乐瓶或 y 个瓶盖可以换一瓶可乐(一瓶可乐包括一个可乐瓶以及一个瓶盖),已知有 a 个空瓶和 b 个瓶盖,问最多能换到多少瓶可乐?
解题思路
解法 1: 首先判断出无限喝可乐的情况,之后模拟空瓶(瓶盖)换可乐即可。无限兑换的情况仅有 x=1 或 y=1 以及 x=y=2 & (a>=2 || b>=2) 。
解法 2: 鉴于上述无限兑换的情况可能容易想漏,故直接模拟也可以。由于 x, y, a, b 都较小,所以选择一个阈值作为上限,到达某个阈值即可视为他在无限兑换。
代码
#include<bits/stdc++.h> using namespace std; int x, y, a, b; int solve() { int cnt = 0; if(x == 1 || y == 1) return -1; if(x == 2 && y == 2 && (a>=2 || b>=2)) return -1; while(a >= x || b >= y) { if(a >= x) a-=x; else if(b >= y) b -= y; else continue; a++, b++, cnt++; } return cnt; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d %d %d %d",&x, &y, &a,&b); int ans = solve(); if(ans == -1) printf("INF\n"); else printf("%d\n", ans); } }
相关文章推荐
- ZOJ - 3948 Marjar Cola 简单模拟
- zoj3948——Marjar Cola
- Marjar Cola(zoj 3948)
- zoj 3948 Marjar Cola
- ACM刷题之ZOJ————Marjar Cola
- zoj 2201 No Brainer
- ZOJ 2476 Total Amount 字符串
- ZOJ2316——Matrix Multiplication
- zoj 3956 01背包
- zoj 1070 Bode Plot
- ZOJ 2334 Monkey King 可并堆左偏树
- ZOJ Gold Coins2345
- ZOJ-2676-Network Wars(01分数规划+最小割)
- zoj 1334 Basically Speaking(进制转换)
- ZOJ-3167
- zoj 3197 Google Book 【区间覆盖】
- ZOJ 2315 New Year Bonus Grant(贪心)
- zoj 1733 Common Subsequence
- ZOJ-1113
- zoj 1745 Are We There Yet?