ZOJ 3948 Marjar Cola
来源:互联网 发布:知乎 陈茂辉 编辑:程序博客网 时间:2024/06/06 04:09
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 个瓶盖,问最多能换到多少瓶可乐?
解题思路
解法 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
- 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
- [DBNETLIB][ConnectionOpen(Invalid Instance())] 无效的连接 的解决办法
- imageview 绑定图片(变形问题)
- Linux内核分析(八)之调兵遣将
- Python+Selenium练习篇之31-获取页面元素的href属性
- 安卓自定义View教程
- ZOJ 3948 Marjar Cola
- 机器学习大热—— LINKZOL深度学习GPU工作站、服务器主机配置深度学习技术
- Mysql 主从
- IGMP协议
- 批量导出多个xml问题
- Linux netstat命令
- Android/Java仿微信按时间长短分类显示时间戳
- 同一进程中的线程共享哪些资源
- 使用markdown写LaTeX公式