注册个人网站域名是com好还是net好,全国建设部网站,北京房山网站建设,简单网页制作素材原题链接#xff1a;https://www.luogu.com.cn/problem/P8627 1. 题目描述 2. 思路分析
小伙伴们可以看看这篇文章~
https://blog.csdn.net/m0_62531913/article/details/132385341?spm1001.2014.3001.5501
我们这里主要讲下方法二的推导过程#xff1a;
列方程。
设最…原题链接https://www.luogu.com.cn/problem/P8627 1. 题目描述 2. 思路分析
小伙伴们可以看看这篇文章~
https://blog.csdn.net/m0_62531913/article/details/132385341?spm1001.2014.3001.5501
我们这里主要讲下方法二的推导过程
列方程。
设最后喝了x瓶饮料则共有x-n瓶饮料是换购来的。因为最后1个瓶盖无法换购那么实际参与了换购的瓶盖只有x-1个。 则可以列出方程x-n(x-1)/3 最后解得x(3*n-1)/2 故答案为(3*n-1)/2
3. 代码实现
3.1 方法一
#includebits/stdc.h
using namespace std;int main()
{int n;cin n;int empty n;int total n;while (empty3){total empty / 3;empty empty / 3 empty % 3;}cout total endl;return 0;
} 3.2 方法二
#includebits/stdc.h
using namespace std;int main()
{int n;cinn;cout(3*n-1)/2;return 0;
} 3.3 方法三
#includebits/stdc.h
using namespace std;int main()
{int n;cin n;int empty 0;while (n){n--;empty;if (empty % 3 0)empty;}cout empty endl;
}