HDU 1396 Counting Triangles
2012-08-07 12:08
309 查看
[align=left]Problem Description[/align]
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
[align=left]Output[/align]
The number of triangles in the equilateral triangle, one per line.
Sample Input
1 2 3
Sample Output
1 5 13
做这个题目要了解,有关数三角形的公式,本质就是一题简单的数学题。
AC代码:
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
[align=left]Output[/align]
The number of triangles in the equilateral triangle, one per line.
Sample Input
1 2 3
Sample Output
1 5 13
做这个题目要了解,有关数三角形的公式,本质就是一题简单的数学题。
AC代码:
#include<iostream> using namespace std; int main() { __int64 a[501]={0,1}; int i,x,y; for(i=2,x=y=0;i<=500;i++) { if(i%2==0){x++;} else {y++;} a[i]=a[i-1]+i*i-x*y; } int n; while(scanf("%d",&n)!=EOF) {printf("%I64d\n",a );} return 0; }
相关文章推荐
- HDU 1396 Counting Triangles
- hdu 1396 Counting Triangles (Dp)
- HDU 1396 Counting Triangles
- [恢]hdu 1396
- HDU 1396 Counting Triangles (找规律)
- HDU-1396 神奇的三角形。坑!
- 【HDU 1396】 【ZOJ 1629】 Counting Triangles
- hdu 1396
- HDU 1396 Counting Triangles
- HDU 1396 && ZJU 1629
- HDU 1396 Counting Triangles
- hdu 1396 Counting Triangles
- HDU 1396 Counting Triangles 递推
- HDU 1396 Counting Triangles
- HDU 1396 Counting Triangles
- hdu 1396
- hdu 1396 Counting Triangles(递推)
- hdu 1396
- hdu 1396 Counting Triangles (递推)
- hdu 1396 Counting Triangles(递推)