首页 > 牛客编程巅峰赛S2赛季第7场
头像
毛裤先生
编辑于 2020-12-09 10:24
+ 关注

牛客编程巅峰赛S2赛季第7场

import java.util.*;


public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 返回牛牛能喝的最多的酒
* @param m int整型 酒单价
* @param n int整型 牛牛的现金
* @return
int整型
*/
private static int beerNum = 0;
private static int addBeerNum = 0;
private static int bottleNum = 0;
private static int libNum = 0;
public int countWine (int m, int n) {
// write code here

addBeerNum = 10 >> 1;
//啤酒数目增加后依次更改啤酒总数、当前空瓶数以及当前瓶盖数
afterAddBeerNumChange(addBeerNum);
//判断当前空瓶数或瓶盖数是否支持继续兑换
while(bottleNum >= 2 || libNum >= 4){
//空瓶数大于2时可兑换
if (bottleNum >= 2) {
//获取兑换啤酒数
addBeerNum = bottleNum >> 1;
//更改当前空瓶数
bottleNum = bottleNum % 2;
//修改啤酒总数、当前空瓶数以及当前瓶盖数
afterAddBeerNumChange(addBeerNum);
}
//瓶盖数大于4时可兑换
if (libNum >= 4) {
//获取兑换啤酒数
addBeerNum = libNum >> 2;
//更改当前瓶盖数
libNum = libNum % 4;
//修改啤酒总数、当前空瓶数以及当前瓶盖数
afterAddBeerNumChange(addBeerNum);
}
}
return -1;
}
private static void afterAddBeerNumChange(int addBeerNum){
beerNum += addBeerNum;
bottleNum += addBeerNum;
libNum += addBeerNum;
System.out.println("beerNum = " + beerNum + " bottleNum = " + bottleNum + " libNum = " + libNum);
}
}

全部评论

(0) 回帖
加载中...
话题 回帖

相关热帖

近期精华帖

热门推荐