南邮 OJ 1380 Tetrahedral Stacks of Cannonballs

Tetrahedral Stacks of Cannonballs

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 44            测试通过 : 33 

比赛描述

    

WALL.ETM, as he cleans up and organizes the depopulated Earth, has come upon some Civil War memorials. He is consolidating the cannonballs into one location, and decides to use pyramids with triangular bases rather than ones with square bases.

In Civil War memorials with cannons and stacks of cannonballs, the cannonballs were sometimes stacked as a four-sided pyramid, with the base as a square of cannonballs with n balls on each side. An alternative is to stack them in a three-sided pyramid, which is in fact one of the Platonic solids, a tetrahedron.

This tetrahedron of cannonballs has a base that is an equilateral triangle of cannonballs with n balls on each side. The number of balls in that triangle is given simply by adding together the numbers from 1 to n. On top of each layer (starting from the base) is a triangle with one less ball on each side, up to the top-most layer with a single ball.

Given the number of cannonballs on each side of the base, compute the total number of cannonballs in the entire tetrahedral stack.




输入

The first line contains a single number n, giving the number of tetrahedral problems posed, for a maximum of 100 problems. Following that are exactly n lines, each with a single number giving the number of cannonballs on each side of the base for a tetrahedron of cannonballs, a number greater than 0 and less than 1000.

输出

For each problem, output the problem number (starting from 1), a colon and a blank, the number of cannonballs on each side of the base, one blank, and finally the total number of cannonballs in the tetrahedron.

样例输入

6
1
2
3
5
27
999

样例输出

1: 1 1
2: 2 4
3: 3 10
4: 5 35
5: 27 3654
6: 999 166666500

提示

undefined

题目来源

2008 ACM-ICPC Pacific Northwest Region



#include<iostream>
#define MAX_N 1001
int a[MAX_N];

int main(){
	int cas,ca,i;
	for(i=1;i<MAX_N;i++){
		a[i] = i;
	}
	for(ca=0;ca<2;ca++){
		for(i=0;i<MAX_N;i++){
			a[i] = a[i-1]+a[i];
		}
	}
	scanf("%d",&cas);
	for(ca=1;ca<=cas;ca++){
		scanf("%d",&i);
		printf("%d: %d %d\n",ca,i,a[i]);
	}
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值