先贴个题目:
以及原题链接: 1216. 饮料换购 - AcWing题库https://www.acwing.com/problem/content/1218/
这题也是纯数学,而且很简单,直接贴代码了。
#include<iostream>
using namespace std;
int main()
{
int n, sum = 0, h, y=0;
cin >> n;
sum += n;
while(n+y>2){
h = (n+y)/3;
y = (n + y) % 3;
n = h;
sum += h;
}
cout << sum;
return 0;
}
by————2024.2.12刷题记录