博客
关于我
第七届蓝桥杯(软件类)省赛C++B组真题题解
阅读量:218 次
发布时间:2019-02-28

本文共 922 字,大约阅读时间需要 3 分钟。

煤球数目

有一堆煤球,堆成三角棱锥形。具体:第一层放1个,第二层3个(排列成三角形),第三层6个(排列成三角形),第四层10个(排列成三角形),……如果一共有100层,共有多少个煤球?


解题思路

每一层的煤球数目形成一个数列,该数列的通项公式为 ( a_i = i(i+1)/2 )。要计算100层的总煤球数目,我们需要对该数列求和。

将数列拆分为 ( a_i = i^2 + i ),因此总和为:[S = \sum_{i=1}^{100} a_i = \sum_{i=1}^{100} \frac{i^2 + i}{2} = \frac{1}{2} \left( \sum_{i=1}^{100} i^2 + \sum_{i=1}^{100} i \right)]

利用已知的求和公式:[\sum_{i=1}^n i = \frac{n(n+1)}{2}, \quad \sum_{i=1}^n i^2 = \frac{n(n+1)(2n+1)}{6}]

代入 ( n = 100 ):[\sum_{i=1}^{100} i = \frac{100 \times 101}{2} = 5050][\sum_{i=1}^{100} i^2 = \frac{100 \times 101 \times 201}{6} = 338350]

因此:[S = \frac{338350 + 5050}{2} = \frac{343400}{2} = 171700]


代码

#include 
using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int maxn = 1e5 + 5;const int mod = 1e9 + 7;void solve() { int temp = 0, ans = 0; for (int i = 1; i <= 100; ++i) { temp += i; ans += temp; } cout << ans << endl;}

答案

171700

转载地址:http://vcsn.baihongyu.com/

你可能感兴趣的文章
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>