Triangular Sums 南阳acm122
Triangular Sums
- 描述
-
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 XWrite a program to compute the weighted sum of triangular numbers:
W(n) =
SUM[k = 1…n; k * 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 - 来源
- Greater New York 2006
- 上传者
- 张云聪
- 题目:比如这个三角形有4层,他的第一层为1.....第四层为4,T(n)=1+2+3+4;但是他不是让我们求T(n),让我们求W(n),W(n)=k*T(k+1); (k=1,2,....n);
- 然后输出的这三位分别是:第一位 1-t(t是多少组测试数据),第二位是 n(就是你输入的n),第三位是 W(n),(英语不好,别见怪哈~) 具体看代码实现:
-
#include<stdio.h>
//用来求T(n),1+2+3+...n;
int f(int n)
{
int i,ans;
ans=;
for(i=;i<=n;i++)
ans+=i;
return ans;
}
int main()
{
int t,a;
a=; //用来计1到t;
scanf("%d",&t);
while(t--)
{
int i,n,k,ans;
ans=;
k=;
scanf("%d",&n);
//用来求W(n)
for(i=;i<n;i++)
{
ans+=(k*f(k+));
k++;
}
printf("%d %d %d\n",a++,n,ans);
}
return ;
}
Triangular Sums 南阳acm122的更多相关文章
- Triangular Sums
描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number ...
- POJ 3086 Triangular Sums (ZOJ 2773)
http://poj.org/problem?id=3086 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1773 让你计算两 ...
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
- NYOJ--122--Triangular Sums
Triangular Sums 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + - + n ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- nyoj 122-Triangular Sums (数学之读懂求和公式的迭代)
122-Triangular Sums 内存限制:64MB 时间限制:3000ms 特判: No 通过数:5 提交数:7 难度:2 题目描述: The nth Triangular number, T ...
- [LeetCode] Find K Pairs with Smallest Sums 找和最小的K对数字
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...
- UVA-11997 K Smallest Sums
UVA - 11997 K Smallest Sums Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
随机推荐
- 《Head First 设计模式》之代理模式
代理模式(Proxy):控制对象访问 ——为另一个对象提供一个替身或占位符来访问这个对象. 要点: 代理模式有许多变体,如:缓存代理.同步代理.防火墙代理和写入时复制代理 代理在结构上类似装饰者,但目 ...
- 关于th,td,tr的一些相关标签
tr表示行,td表示列,th其实也是表示列但是在这个标签中的文字会以粗体出现 <th>为表格标题,属性summar为摘要, <caption>标签为首部说明, <thea ...
- FAT12格式的引导区实现
org 07c00h ;================================================ jmp short START nop ; 这个 nop 不可少 ;这个结构将 ...
- SQLServer 2012 Ent 安装失败,另辟蹊径
今天配到SqlServer2012 安装不了问题,总是NetFX3,然后一次挂了,然后VS2010 Shell也是个悲剧. 装了VS2010,可以了吧,总不能在不给力吧.但是有提示VS2010是打上s ...
- linux下使用iperf测试服务器带宽
准备工具 1.2台Linux服务器(要求其中至少1台主机为腾讯云主机,另外一台任意主机均可,确保2台主机可以互相访问即可)2.Iperf软件为专业网络性能测试工具. 测试目标 上海地区主机外网带宽是否 ...
- Git的使用(详细)
一下内容引自网络 原帖:http://blog.jobbole.com/78960/ 原文出处: 涂根华的博客
- 笨办法学Python(九)
习题 9: 打印,打印,打印 # Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed T ...
- 洛谷 P1080 国王游戏
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王站在队伍的最 ...
- 洛谷 P1849 [USACO12MAR]拖拉机Tractor
题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle ...
- 如何把某个网站的SSL Server certificate链导入到ABAP Netweaver系统里
我们在用ABAP代码消费外网的url时会遇到一些异常,比如ICM_HTTP_SSL_PEER_CERT_UNTRUSTED,这是因为请求的url所在的网站的SSL Server certificate ...