题意:

  有一个金币堆的金字塔,最上层就有一个金币,以后的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. 临远大神,你为啥要建立一个 TASK表。HumanTaskDTO

    临远大神,你为啥要建立一个 TASK表.HumanTaskDTO HumanTask这张表的作用是什么. 为了实现理想中的任务中心.TaskCenter. 首先,工作流可能会完全不包含任何人工节点,全 ...

  2. SeaGlass:手工搭建伪基站监控系统

    “伪基站”即假基站,设备一般由主机和笔记本电脑或手机组成,通过短信群发器.短信发信机等相关设备能够搜取以其为中心.一定半径范围内的手机卡信息,利用2G移动通信的缺陷,通过伪装成运营商的基站,冒用他人手 ...

  3. [NPM] Create a new project using the npm init <initializer> command

    Historically, the npm init command was solely use to create a new package.json file. However, as of ...

  4. Zookeeper 简单操作

    1.  连接到zookeeper服务 [java2000_wl@localhost zookeeper-3]$ bin/zkCli.sh -server 127.0.0.1:2181 也可以连接远端的 ...

  5. Python开发【1.1 基础语法】

    1.Python语言特点 优点: ①.丰富的库 ②.简单.开源 ③.支持面向对象编程 ④.解释性语言,无需编译 ⑤.高层语言,不用考虑内存问题 ⑥.可移植性好,不依赖于操作系统 缺点: ①.运行效率较 ...

  6. qemu -net tap配置上网

    1 该选项的用途 让qemu所在的宿主机器的tap网络接口和qemu的vlan n连接起来,从而进一步配置宿主机后,可以让qemu里面的操作系统可以通过vlan n里面的网卡上网. 2 真个系统的架构 ...

  7. win10复制粘贴 失效

    win10复制粘贴 DISM.exe /Online /Cleanup-image /Restorehealth https://social.technet.microsoft.com/Forums ...

  8. LeetCode 7. Reverse Integer (JS)

    Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...

  9. POJ3177 Redundant Paths —— 边双联通分量 + 缩点

    题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total ...

  10. webstorm使用帮助(转自http://my.oschina.net/longteng2013/blog/138010),另外有部分内容摘自其它人博客

    为了更高效的开发代码,这里列出了一些webstorm的快捷键和zencoding 发表于1 年 前(2013-06-17 00:19)   阅读(2101) | 评论(2) 11人收藏此文章, 我要收 ...