咱先看看能怎么分
- 25+25=50
- 18+21+21=60
- 18+18+18=54
再一想,得到这个算式
(25+25)∗3+(18+21+21)∗3+(18+18+18)∗2
就等于
(25+21+18)∗6
这就用了 3+3+2=7 个木板,做了 6 组。
那剩下的 0∼5 组,浅浅模拟一下。
- 0 组,用 0 个木板;
- 1 组,用 2 个木板;
- 2 组,用 3 个木板;
- 3 组,用 4 个木板;
- 4 组,用 5 个木板;
- 5 组,用 6 个木板;
最后,把上面的结果拿数组存起来,最后输出 floor(n/6)∗7+anmod6 即可。
代码
C++#include<bits/stdc++.h>//万能头
using namespace std;
int n;//定义n
int a[]={0,2,3,4,5,6,7};//定义0到6中用的木板数
int main(){
cin>>n;//输入n
cout<<(n/6)*7+a[n%6]<<endl;//输出答案
return 0;//开心的结束了
}