UVA 11401 Triangle Counting(数学)

Problem GTriangle Counting

Input: StandardInput

Output: StandardOutput 

You are given n rods oflength 1, 2…, n. You have to pick any 3 of them & build a triangle. Howmany distinct triangles can you make? Note that, two triangles will beconsidered different if they have at least 1 pair of arms with differentlength.

 

Input

The input for each case will have only a single positive integern (3<=n<=1000000). The end ofinput will be indicated by a case withn<3.This case should not be processed.

Output

For each test case, print the number of distinct triangles you canmake.

Sample Input                                                                   Output for Sample Input

5                                                         

8

0

                                                                      3

                                                                    22

Problemsetter: Mohammad Mahmudur Rahman


每次做这种三角形的题的时候,我就想到了三角恋,然后就有一种想挖别人墙角的感觉,世界观啊,情商啊,更年期啊。。。看电视剧的时候也是一样,总是支持反派,这情况好像不太正常。。。。(飙泪中。。。)


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define MAXN 1000000+10
using namespace std;

typedef unsigned long long ULL;
ULL a[MAXN];

int main()
{
    a[3] = 0;
    for(ULL i=4; i<MAXN; i++) {
        a[i] = a[i-1] + ((i-1)*(i-2)/2-(i-1)/2)/2;
    }
    ULL n;
    while(~scanf("%lld", &n)) {
        if(n < 3) break;
        printf("%lld\n", a[n]);
    }
    return 0;
}
代码有点短是吧,没办法啦,水平有限+更年期,真是不容易啊。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值