题意:

  有一个金币堆的金字塔,最上层就有一个金币,以后的i层都是边长为i的实心三角形,给你层数,问:一共有多少个金币?(用科学计数法表示,并且保留两位小数)

解题思路:

  根据题意可知求出1*n+2*(n-1)+3*(n-2)+4*(n-3)+.......+(n-2)*3+(n-1)*2+n*1的和即可,但是要化简一下求出n*(n+1)*(n+2)/6;

证明:

  1 * n + 2 (n - 1) + 3 (n - 2) + …… + (n - 2) * 3 + (n - 1) * 2 + n * 1

  = 1 * (n + 1 - 1) + 2 (n + 1 - 2) + 3 (n + 1 - 3) + …… + (n - 2) * (n + 1 - (n - 2)) + (n - 1) * (n + 1 - n - 1) + n * (n + 1 - n)

  =(1 + 2 + 3 + ... + n)(n + 1) - (1^2 + 2^2 + 3^2 + ..... + n^2)

  =n (n + 1)^2 / 2 - n (n + 1) (2n + 1) / 6       (n (n + 1) (2n + 1) / 6后面会证明)

  =n * (n + 1) * (n + 2) / 6          (证毕)

  (n+1)^3-n^3=3n^2+3n+1,

  n^3-(n-1)^3=3(n-1)^2+3(n-1)+1

  

  3^3-2^3=3*(2^2)+3*2+1

  2^3-1^3=3*(1^2)+3*1+1.

  这n个等式两边分别相加得出:

  (n+1)^3-1=3(1^2+2^2+3^2+....+n^2)+3(1+2+3+...+n)+n,

  (n+1)^3-1=3(1^2+2^2+3^2+....+n^2)+3((n+1)n/2)+n,

  整理可得上述式子。

代码:

 #include <stdio.h>
int main ()
{
int n, i, k;
double s; while (scanf ("%d", &n), n)
{
s = 1.0 * n * (n+) * (n+) / ;
k = ;
while (s >= )
{
s /= ;
k++;
}
printf ("%.2fE%d\n", s, k);
} return ;
}
  
 

hdu 1178 Heritage from father (推导)的更多相关文章

  1. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

  2. hdu 5312 Sequence(数学推导——三角形数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)  ...

  3. HDU 5826 physics (积分推导)

    physics 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5826 Description There are n balls on a smoo ...

  4. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  5. Heritage from father

    Problem Description Famous Harry Potter,who seemd to be a normal and poor boy,is actually a wizard.E ...

  6. HDOJ/HDU 1297 Children’s Queue(推导~大数)

    Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...

  7. HDOJ(HDU) 2524 矩形A + B(推导公式、)

    Problem Description 给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格. Input 第一行输入一个t, 表示有t组数据,然后每行输入n,m ...

  8. HDOJ(HDU) 1977 Consecutive sum II(推导、、)

    Problem Description Consecutive sum come again. Are you ready? Go ~~ 1 = 0 + 1 2+3+4 = 1 + 8 5+6+7+8 ...

  9. hdu 5312 Sequence(数学推导+线性探查(两数相加版))

    Problem Description Today, Soda has learned a sequence whose n-th (n≥) item )+. Now he wants to know ...

随机推荐

  1. jenkins节约硬盘空间的几个办法

    jenkins真是费硬盘和内存,我们先聊聊硬盘问题怎么解决: 1.不要保留太多的构建记录.发布包数量 相关描述如下:取最先匹配进行执行 2.构建完,删除吧

  2. 【安卓笔记】抽屉式布局----DrawerLayout

    效果例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hkamo=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  3. Codeforces div.2 B. The Child and Set

    题目例如以下: B. The Child and Set time limit per test 1 second memory limit per test 256 megabytes input ...

  4. C#建立最简单的web服务,无需IIS

    软件架构师何志丹 本程序仅仅是入门级程序.所以不考虑 1.多线程. 2,安全性. 3,不考虑端点下载文件. 4,Keep-Alive. 5,不考虑head. 6,为了简洁,删掉了catch的内容. e ...

  5. leetcode_Repeated DNA Sequences

    描写叙述: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &qu ...

  6. CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)

    C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. python itertools

    1 product 1.1 一个generator函数 因此它的返回值是一个iterator,可以用for遍历. 1.2 计算product的参数分类 1.2.1 dict和list 只用了dict的 ...

  8. ASP.NET Web Pages (Razor) API Quick Reference

    ASP.NET Web Pages (Razor) API Quick Reference By Tom FitzMacken|February 10, 2014 Print This page co ...

  9. Oracle - 查询语句 - 多表关联查询

    /* SQL语句的历史版本 SQL89 比较多 SQL92 SQL99 多表关联查询 笛卡尔积 等值关联查询 非等值关联查询 左外连接 右外连接 全外连接 自连接 */ --------------- ...

  10. GrideView(二)---删除功能

    情景一. 没有外键关联, 操作:在数据源中将删除选项选中--- GrideView 中的删除 选项选中 即可情景二. 有外键关联 *RowDeleting 行删除前触发 *RowDeleted 行删除 ...