题目描述
思路
一是可以多枚举几个数,找找规律
二可以模拟
代码
#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遍还是不会,自己理解起来就很难,瓶子分为答案和瓶盖,分别相加