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. EditText判断用户输入完成,然后进行操作解决方案

    private Timer timer = new Timer(); private final long DELAY = 1000; // in ms EditText editTextStop = ...

  2. python运维开发(十七)----jQuery续(示例)web框架django

    内容目录: jQuery示例 前端插件 web框架 Django框架 jQuery示例 dom事件绑定,dom绑定在form表单提交按钮地方都会绑定一个onclick事件,所有查看网站的人都能看到代码 ...

  3. 使用Calendar增加日期

    /** * @Description: 当前日期加上n个月返回long date */ public static long getLongDateAddMonth(int n){ Calendar ...

  4. 剑指offer-面试题17.合并两个排序的链表

    题目:输入两个递增的排序的链表,合并这两个链表并使新链表中的节点仍然是 按照递增排序的.例如链表1链表2合并为链表3. List1:->->-> List2:->->-& ...

  5. xen vhd操作工具source code研读

    推出最新的VHD操作工具VHD-UTIL 实现源码,超强,Ruiy只为学习高手的设计思路

  6. DataTable转换成List

    public static List<T> GetList<T>(DataTable table) { List<T> list = new List<T&g ...

  7. php 原理相关

    [PHP 运行方式(PHP SAPI介绍)] http://www.phpddt.com/php/php-sapi.html [PHP内核探索:从SAPI接口开始]http://www.nowamag ...

  8. Windows7&IIS7.5部署Discuz

    IIS CGI一定要安装 IIS 网站中添加关联程序 ,添加默认文档 http://www.cnblogs.com/ajunForNet/archive/2012/09/12/2682063.html

  9. Spring的MethodInvokingFactoryBean

    通过MethodInvokingFactoryBean 可以向某静态方法注入参数. 如: <bean class="org.springframework.beans.factory. ...

  10. 怎样为virtualbox添加新的分辨率

    virtualbox是个相当NB的开源跨平台虚拟机软件,只是新创建的虚拟机仅仅支持几种分辨率.比如.安装win8.1,仅仅有例如以下图的几种分辨率. 只是我的显示器是5K哦,这么点分辨率,简直是搞笑. ...