122-Triangular Sums

内存限制:64MB
时间限制:3000ms
特判: No

通过数:5
提交数:7
难度:2

题目描述:

The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number of points in a triangular array with n points on side. For example T(4):

X
X X
X X X
X X X X

Write a program to compute the weighted sum of triangular numbers:

W(n) = SUM[k = 1…nk * T(k + 1)]

输入描述:

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer n, (1 ≤ n ≤300), which is the number of points on a side of the triangle.

输出描述:

For each dataset, output on a single line the dataset number (1 through N), a blank, the value of n for the dataset, a blank, and the weighted sum ,W(n), of triangular numbers for n.

样例输入:

复制

4
3
4
5
10

样例输出:

1 3 45
2 4 105
3 5 210
4 10 2145

C/C++ AC:

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <climits> using namespace std;
const int MY_MAX = ;
int T[MY_MAX] = {}, W[MY_MAX] = {}, n; void cal_W()
{
T[] = , T[] = ;
for (int i = ; i < MY_MAX - ; ++ i)
{
W[i] = W[i - ] + i * T[i + ];
T[i + ] = T[i + ] + i + ;
}
} int main()
{
cal_W();
cin >>n;
for (int i = ; i <= n; ++ i)
{
int temp;
scanf("%d", &temp);
printf("%d %d %d\n", i, temp, W[temp]);
}
}

最新文章

  1. Animation
  2. 《Android深度探索HAL与驱动开发》第一章阅读心得
  3. 实验12:Problem C: 重载字符的加减法
  4. 输入的全角字符转换成半角字符--css、js、ASP.NET
  5. JS模块化工具requirejs教程(一):初识requirejs
  6. 正整数的n次方求和
  7. mysql中显示方式的切换
  8. Jersey的RESTful简单案例demo
  9. php header设置页面编码
  10. Linux指令--which,whereis,locate,find
  11. Spark内存管理-UnifiedMemoryManager和StaticMemoryManager
  12. Android 仿百合网超火爆社交app首页滑动效果
  13. python -yield理解
  14. CentOS开机提示kernel panic - not syncing: Attempted to kill init! 解决方法
  15. 了解一下vue源码中vue 的由来
  16. 使用gitbook plugin
  17. .net core内部分享ppt
  18. Linux常用命令大全(新手入门)
  19. 拯救U盘之——轻松修复U盘“无法访问”的故障
  20. 【Ubuntu】录屏软件

热门文章

  1. Math中ceil中为什么会有负零
  2. Unity - Raycast 射线检测
  3. HTTP使用get,post方式连接
  4. Python爬取散文网散文
  5. 数据结构c语言
  6. Python 常见异常类型
  7. kafka里的一些管理脚本
  8. 误删除 mySQL 用户解决办法
  9. Cannot read property &#39;forEach&#39; of undefined
  10. fenby C语言 P17