前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ-Counting Triangles

HDUOJ-Counting Triangles

作者头像
Gxjun
发布2018-03-21 11:41:51
8060
发布2018-03-21 11:41:51
举报
文章被收录于专栏:mlml

Counting Triangles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1882    Accepted Submission(s): 898

Problem Description

Given an equilateral triangle with n the length of its side, program to count how many triangles in it.

Input

The length n (n <= 500) of the equilateral triangle's side, one per line. process to the end of the file

Output

The number of triangles in the equilateral triangle, one per line.

Sample Input

1 2 3

Sample Output

1 5 13

Author

JIANG, Jiefeng

Source

http://acm.hdu.edu.cn/showproblem.php?pid=1396

Recommend

Ignatius.L

规律在这:

http://mathworld.wolfram.com/TriangleTiling.html

代码:

代码语言:javascript
复制
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    int sum;
    while(cin>>n)
    {
        sum=n*(n+2)*(2*n+1);
        if(n&1)    sum--;
        printf("%d\n",sum/8);
    }
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-08-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Counting Triangles
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档