hdu 1178 Heritage from father (推导)
题意:
有一个金币堆的金字塔,最上层就有一个金币,以后的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 (推导)的更多相关文章
- HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)
Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...
- hdu 5312 Sequence(数学推导——三角形数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others) ...
- HDU 5826 physics (积分推导)
physics 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5826 Description There are n balls on a smoo ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- Heritage from father
Problem Description Famous Harry Potter,who seemd to be a normal and poor boy,is actually a wizard.E ...
- HDOJ/HDU 1297 Children’s Queue(推导~大数)
Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...
- HDOJ(HDU) 2524 矩形A + B(推导公式、)
Problem Description 给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格. Input 第一行输入一个t, 表示有t组数据,然后每行输入n,m ...
- 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 ...
- hdu 5312 Sequence(数学推导+线性探查(两数相加版))
Problem Description Today, Soda has learned a sequence whose n-th (n≥) item )+. Now he wants to know ...
随机推荐
- 使用引导光盘,将你的PC变身瘦客户机
很多国内使用VMware View桌面虚拟化产品的朋友问我,是否可以将自己现有的PC改造成一台瘦客户机呢? 一方面即可以得到桌面虚拟化的管理,安全的好处,而且连前端PC机的系统管理的工作都省了? 答案 ...
- 【Git使用具体解释】Egit的经常使用操作具体解释
经常使用操作 操作 说明 Fetch 从远程获取最新版本号到本地,不会自己主动merge Merge 能够把一个分支标签或某个commit的改动合并如今的分支上 Pull 从远程获取最新版本号并mer ...
- Word 2013安裝字典
不必從內建的字典中開始,Word 2013 可將您連結到 Office 市集,方便您挑選免費的字典,或從包括多語字典的字典集合中購買. 若要選擇並安裝您想要的字典,請以滑鼠右鍵按一下任何單字,並按一下 ...
- [Bash] Search for Text with `grep`
In this lesson, we’ll use grep to find text patterns. We’ll also go over some of the flags that grep ...
- iOS国际化:NSLocalizedString的使用
因为iOS和XCode版本号更新得太快的原因,导致网上非常多文章都失去了时效性,或许再过两三个月我这篇文章也将走上这条路,但起码能够让现阶段看到的人对iOS的国际化有个比較清楚的认识. NSLocal ...
- 重载OverLoad。隐藏new
<1> using System; using System.Collections.Generic; using System.Linq; using System.Text; name ...
- ZOJ 2706 Thermal Death of the Universe (线段树)
题目链接:ZOJ 2706 Thermal Death of the Universe (线段树) 题意:n个数.m个操作. 每一个操作(a,b)表示(a,b)全部值更新为这个区间的平均数:1.当前的 ...
- leetcode:122. Best Time to Buy and Sell Stock II(java)解答
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Best Time to Buy and Sell Stock II Say you have an array for which th ...
- STM32通过调用库函数进行编程
1.调用库函数编程和直接配置寄存器编程的差别: 2.CMSIS标准: 3.STM32库函数的组织: 4.程序例举: 调用库函数实现通过USART发送数据(26个大写的英文字母) 首先:在主函数部分先要 ...
- 朴素的标题:MVC中权限管理实践
基于MVC的web项目最好的权限控制方式我认为是对Action的控制,实现思路记录于此,权限管理分成两个部分授权.认证. 一.授权 1.读取当前项目中的所有需要控制的Action /// <su ...