Counting Triangles

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

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
  分正三角形和倒三角形,
  当长度为n时,在最低边上长度为x的正三角形,个数为n-x+1,所以总的个数为(n-x+1+1)*(n-x+1)/2
          在最低边上长度为x的倒三角形,个数为n-x*2+1(2*x<=n),所以总的个数为(n-2*x+1+1)*(n-2*x+1)/2;
 #include <iostream>
using namespace std;
int main()
{
int n,i,j;
long long a[]={};
for(i=;i<;i++)
{
for(j=;j<=i;j++)
{
a[i]+=(i-j++)*(i-j+)/;
if(j*<=i)
a[i]+=(i-*j++)*(i-*j+)/;
}
}
while(cin>>n)
cout<<a[n]<<endl;
}
 

Counting Triangles(hd1396)的更多相关文章

  1. hdu 1396 Counting Triangles(递推)

    Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, p ...

  2. UVA 12075 - Counting Triangles(容斥原理计数)

    题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...

  3. 1307 - Counting Triangles

    1307 - Counting Triangles    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  4. LA 3295 (计数 容斥原理) Counting Triangles

    如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单: ...

  5. UVALive 3295 Counting Triangles

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UVA 12075 Counting Triangles

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  7. UVA 1393 Highways,UVA 12075 Counting Triangles —— (组合数,dp)

    先看第一题,有n*m个点,求在这些点中,有多少条直线,经过了至少两点,且不是水平的也不是竖直的. 分析:由于对称性,我们只要求一个方向的线即可.该题分成两个过程,第一个过程是求出n*m的矩形中,dp[ ...

  8. Codestorm:Counting Triangles 查各种三角形的个数

    题目链接:https://www.hackerrank.com/contests/codestorm/challenges/ilia 这周六玩了一天的Codestorm,这个题目是真的很好玩,无奈只做 ...

  9. HDUOJ-Counting Triangles

    Counting Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. 几个STL算法:includes,set_difference、set_intersection、set_symmetric_difference、set_union, pre_permutation, next_permutation

    includes: 测试有序序列中是否包含另一个序列的全部元素. template<class inputIterator1, class inputIterator2> bool inc ...

  2. web.py安装

    web.py 是python的一个web插件,用于发布web服务安装下载web.py https://github.com/webpy/webpy 安装 解压下载的rar 打开控制台并定位到此文件夹输 ...

  3. python 求MD5值

    (一)求字符串的MD5值 import hashlib #导入功能模块,此模块有MD5,SHA1,SHA256等方法 m = hashlib.md5() #声明一个对象 m.update(b'hell ...

  4. H5+Boostrap的音乐播放器

    H5+Boostrap做简单的音乐播放器 前言:这个是综合一下我最近在学的东西做的小Demo,到实际使用还有距离,但是用来练手巩固知识点还是不错的,最近在二刷JS书和Boostrap.css的源码,做 ...

  5. C++ Primer day 01

    1.标准输入与输出 #include<iostream> int main(){ int v1,v2; std::cout<<"Enter two numbers:& ...

  6. Oracle的几种索引

    Oracle 提供了多种不同类型的索引以供使用.简单地说, Oracle 中包括如下索引: 1. B* 树索引 这些是我所说的 “ 传统 “ 索引.到目前为止,这是 Oracle 和大多数其他数据库中 ...

  7. Android高德地图开发具体解释

    这段时间开发的时候用到了高德地图,对高德地图开发有心得体会,如今分享给大家.对我开发过百度地图的我来说,整体来说高德地图Demo,没有百度解说的具体 个人更偏向于使用百度地图,可是没办发,项目须要使用 ...

  8. 遇到的Fragment中使用setAdapter()设置ListView报空指针解决方案

    场景是这样,底部4个tab导航栏.用的fragment. 但其中一个fragmentActivity1中使用ListVIew的setAdapter()方法时,总是报NullPointerExcepti ...

  9. 【转】Android下编译jni库的二种方法(含示例) -- 不错

    原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从N ...

  10. codecomb 2098【stone】

    题目描述 Description n个石堆围成一圈,提供两种操作: 1.每次将[L,R]堆的石子数量+k,其中,1<=L,R<=n,k>=0. 2.询问有最多石子的那一堆有多少石子. ...