怎么给喜欢的人做网站,产品营销方案,帝国做的网站怎么上传图片,精准数据库营销文章目录1. 题目2. 解题1. 题目
链接#xff1a;https://ac.nowcoder.com/acm/contest/9752/A 来源#xff1a;牛客网
牛牛是一个酒鬼#xff0c;非常爱喝酒#xff0c; 一瓶酒m元钱#xff0c; 两个酒瓶可以换一瓶酒#xff0c; 四个瓶盖可以换一瓶酒#xff0c; 现在…
文章目录1. 题目2. 解题1. 题目
链接https://ac.nowcoder.com/acm/contest/9752/A 来源牛客网
牛牛是一个酒鬼非常爱喝酒 一瓶酒m元钱 两个酒瓶可以换一瓶酒 四个瓶盖可以换一瓶酒 现在有 n 元钱求最多可以喝多少瓶酒 注没有借贷功能即最终不允许借一瓶酒、喝完后拿酒瓶兑换归还的操作
示例1
输入
2,12
返回值
19
说明
牛牛总计可以喝19瓶酒备注:
0 m 100
0 n 20002. 解题
class Solution {
public:/*** 代码中的类名、方法名、参数名已经指定请勿修改直接返回方法规定的值即可* 返回牛牛能喝的最多的酒* param m int整型 酒单价* param n int整型 牛牛的现金* return int整型*/int countWine(int m, int n) {// write code hereif(n m) return 0;int ans 0, gai 0, bottle 0;while(n/mgai/4bottle/2 0){int newWine1 n/m;n - newWine1*m;ans newWine1;gai newWine1;bottle newWine1;int newWine2 gai/4;gai -newWine2*4newWine2;bottle newWine2;ans newWine2;int newWine3 bottle/2;gai newWine3;bottle -newWine3*2newWine3;ans newWine3;}return ans;}
};我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步