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. shell脚本练习

    写一个脚本:1.设定变量FILE的值为/etc/passwd2.依次向/etc/passwd中的每个用户问好,并显示对方的shell,形如: Hello, root, your shell: /bin ...

  2. Loadrunner11 录制手机App脚本多种方法介绍

    总体来说,通过LR录制手机脚本的方式有三种:1)通过代理方式录制,保证手机电脑在同一个网段:2)通过抓包录制,在手机上安装Mobile Recorder:3)通过安卓模拟器录制,本地安装Android ...

  3. jsp执行数据库查询并分页

    需求: 有一批企业的基本信息需要展示出来,要求一级页以列表形式展示企业清单,点击公司名称后进入二级页面,二级页面展示企业简介和几张图片. 实现效果: 开发环境: Win7,Eclipse,Mysql ...

  4. Ubuntu14.04安装PostpreSQL9.3.5记录

    安装参考:http://www.postgresql.org/download/linux/ubuntu/ y@y:~$ sudo apt-get install postgresql-9.3 pos ...

  5. Extjs Tooltip属性的使用

    要想让 tooltip生效必须:Ext.QuickTips.init();

  6. Android 打开URL

    打开链接 Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com")); it.set ...

  7. Hamming code

    Also known as (7,4) code,7 trainsmitted bits for 4 source code. TRANSMIT The transmitted procedure c ...

  8. Canvas API -- JavaScript 标准参考教程(alpha)

    Canvas API -- JavaScript 标准参考教程(alpha) Canvas API

  9. 第一个MyBatis程序

    最近研究了一些MyBatis技术,虽然工作中还未用到,但是觉得了解一下也是不错的.这里记录了第一个简单的Demo程序,防止自己忘记. 第一步需要配置Mybatis-config.xml文件.注意:这里 ...

  10. MyEclipse 注册码

    MyEclipse 注册码和大家共享一下! 一:MyEclipse_6.0.1GA_E3.3.1_FullStackInstaller注册码 Subscriber:javp Subscription ...