题目详情:
思路:
每e个酒瓶可以换1个酒瓶,相当于每减少e-1瓶酒,就可以换喝一瓶酒 那公式岂不是 n/(e-1)了?
但是有个前提,就是最后至少有e瓶酒才可以兑换,如果最后只剩e-1瓶酒就不能再换了。 所以公式为(n-1)/(e-1)。
这样最后只剩e-1瓶酒的时候,就不足以被e-1整除而多兑换一次。
模拟样例:
代码部分:
// 方法一:数学方法
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;cin>>n;
cout<<n+(n-1)/2<<endl;
return 0;
}
// 方法二:循环
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;cin>>n;
int res=n;
while(n>=3)
{
n-=2;//失去三个瓶盖,给一个瓶盖,相当于失去两个瓶盖
res++;
}
cout<<res<<endl;
return 0;
}
// 方法三:瞎猫碰见死耗子 被我蒙对了
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;cin>>n;
int res=n;// 酒瓶的记录总数
int s=n; //每次兑换完后还剩多少瓶盖 刚开始为n
while(s>=3)// 当瓶盖小于三个的时候不能再兑换了
{
res+=s/3;
s=s/3+s%3;
}
cout<<res<<endl;
}
- 小学奥数题 困扰了我老半天 无比惭愧! 请各位大佬多多指教