题目描述

思路
一是可以多枚举几个数,找找规律
二可以模拟
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+10;
int a[N];
int b[N]; //前缀和
signed main()
{
int n;
cin >> n; //表示初始的饮料盖
int ans = n;
int temp = 0; //表示不够3个的
while(n >= 3) //只要饮料盖大于等于3,就能换购
{
temp = n % 3; //表示不够3个的
ans += n /3; //能换购的饮料数
n /= 3; //够3个,产生的瓶盖
n += temp ; //再加上换购的那些
}
cout<<ans<<endl;
return 0;
}
或者直接找规律

总结
做了n遍还是不会,自己理解起来就很难,瓶子分为答案和瓶盖,分别相加


![[UEC++]UE5C++各类变量相关知识及其API(更新中)](https://i-blog.csdnimg.cn/direct/1fa6e22e30d84dc1858c57232c0e09a1.png)


![[Effective C++]条款30:透彻了解inlining的里里外外](https://i-blog.csdnimg.cn/direct/e4d3cbd3f39e4e719044cb86b2409cf7.png)













