日期:2014-05-20  浏览次数:20745 次

问个题目
有304瓶啤酒,每3个空瓶子能换一瓶新啤酒,问能喝到多少瓶啤酒?这个解题目的思路是什么?


------解决方案--------------------
3个空瓶喝一个 剩一个空瓶

相当于2个空瓶 喝一个

a=304/2

余0 a-1
余1 a


public class wer
{
public static int res(int m,int n)
{
int re=0;
n=n-1;

re=(m%n==0)?(m/n-1):(m/n);

return re;

}


public static void main(String[] args)
{
int result;

result=res(305,3);


System.out.println(result);

}
}
------解决方案--------------------
public class Peer{
private static int num=0;//记录总共喝的数目
private static int i=0;//记录下一次换酒后的数目
public static void totalPeer(int n){
num+=n-n%3;
i=n%3+(n-(n%3))/3;
if(i <3)num+=i;
else{
//System.out.println(num);
totalPeer(i);
}
}
public static void main(String[] args){
totalPeer(304);
System.out.println( "The total peer you can drink is: "+num);
}
}
输出:
The total peer you can drink is: 455
没有考虑有关怎样换啤酒的方法。
------解决方案--------------------
呵呵,等一下。