牛客编程巅峰赛S2第七场
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 返回牛牛能喝的最多的酒
* @param m int整型 酒单价
* @param n int整型 牛牛的现金
* @return int整型
*/
public int countWine (int m, int n) {
// write code here
int x = 0;
int y = 0;
int a = 0;
int b = 0;
int ans = n/m;
int cout = 0;
while(true){
cout += ans;
x = (ans+a)/2;
y = (ans+b)/4;
if((ans+a) % 2 != 0) a = 1;
else a = 0;
if((ans+b) %4 != 0) b = (ans+b) %4;
else b = 0;
ans = x + y;
if(ans == 0) break;
}
return cout;
}
}
#题解#


查看24道真题和解析