int nPingZiCount=100;//每次瓶子的数目,最开始是100int nResult=0;//可以喝的水数目do { nResult+=nPingZiCount; nPingZiCount=nPingZiCount/2; } while(nPingZiCount>0);//结果在nResult中,
确切地说是 int n = 100 / 1; int result = n * 2 - 1;
<script type="text/javascript"> var howMuchBottle = 0; function count(totalMoney) { var i = 1; while (i < totalMoney && i != totalMoney) { howMuchBottle += Math.floor(totalMoney / i); i *= 2; } return howMuchBottle++; } alert(count(20)); </script>
int i = 100; //瓶子数 int sum = 0; //喝到多少瓶水 sum = i; while (i > 1) { sum += i / 2; i = i % 2 + i / 2; }
int nCount = money; int nResult = 0; nResult += nCount; while (nCount > 1) { nCount -= 2; nResult++; nCount += 1; } Console.WriteLine(nResult);
int nCount = money; int nResult = 0; nResult += nCount; while (nCount > 1) { nCount -= 2; nResult++; nCount += 1; } Console.WriteLine(nResult);
想要什么样的解法啊。很多种的。程序算法:int kp=100; int he=100; int nhe=0; do { nhe=kp/2; he+=nhe; kp=kp/2+kp%2; } while(kp>=2); printf("%d\n",he);
int nPingZiCount=100;//每次瓶子的数目,最开始是100int nResult=0;//可以喝的水数目do
{
nResult+=nPingZiCount;
nPingZiCount=nPingZiCount/2;
}
while(nPingZiCount>0);//结果在nResult中,
int n = 100 / 1;
int result = n * 2 - 1;
var howMuchBottle = 0;
function count(totalMoney) {
var i = 1;
while (i < totalMoney && i != totalMoney) {
howMuchBottle += Math.floor(totalMoney / i);
i *= 2;
}
return howMuchBottle++;
} alert(count(20));
</script>
int sum = 0; //喝到多少瓶水
sum = i;
while (i > 1)
{
sum += i / 2;
i = i % 2 + i / 2;
}
int nResult = 0;
nResult += nCount; while (nCount > 1)
{
nCount -= 2;
nResult++;
nCount += 1;
}
Console.WriteLine(nResult);
int nResult = 0;
nResult += nCount; while (nCount > 1)
{
nCount -= 2;
nResult++;
nCount += 1;
}
Console.WriteLine(nResult);
int he=100;
int nhe=0;
do
{
nhe=kp/2;
he+=nhe;
kp=kp/2+kp%2;
}
while(kp>=2);
printf("%d\n",he);