SPOJ 1167(Move To Invert-三角形硬币阵颠倒)

SPOJ Problem Set (classical)

1167. Move To Invert

Problem code: MINCOUNT

将左边的三角形变成右边这样至少需要挪几枚硬币?  

For h=4 at least 3 coins must be moved to invert it.

Input

In the first line N will be given and then N lines follow with each line having a integer which is the height of triangle in that test case.00≤h<1010;

Output

For each test case output in a seperate line the minimum number of moves required to invert the triangle. Output fits in long long data type

Example

Inputt:
1
3

Output:
2

答案是n(n+1) div 6
这是纯粹的打表找规律题……
注意Comments中对%lli的注解(等待C++有识之士解释……)
#include<cstdio>
#include<cstring>
using namespace std;
unsigned long long n;
int main()
{
	scanf("%lli",&n);
	while (scanf("%lli",&n)!=EOF) printf("%lli\n",n*(n+1)/6);
	return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值