AcWing 1216. 饮料换购
原题链接
简单
作者:
小小龙_1
,
2024-03-14 18:25:36
,
所有人可见
,
阅读 12
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int res = 0;
res = n;
while (n >= 3)
{
res += n / 3;
n = n / 3 + n % 3; // 总共的盖子数
}
cout << res << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int res = 0, r = 0;
int ans = 0;
while (n > 0)
{ // 100 33(1) 11(0) 3(2) 1(1 + 2/ 3 ) + 1
res += n; // res 原买瓶盖
ans += n % 3; // ans 新买一瓶后剩余的瓶盖 100 % 3 = 1
n /= 3; // + 新购买瓶盖 100 / 3 = 33
r = ans / 3;
}
cout << res + r << endl;
return 0;
}