UVA 11401 Triangle Counting(数学)

来源:互联网 发布:mysql 默认 编辑:程序博客网 时间:2024/04/21 00:27

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+10using 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
原创粉丝点击