/*此题的分析思路为边长为n的等边三角形,变为边长为n+1的等边三角形,边长为1的三角形增加了多少个,边长为2的三角形增加了多少个,
都是有规律的,注意三角形有上有下。。。*/
#include <iostream>
#include <cstdio>
using namespace std;
int A[508];
int main()
{
A[1]=1;
for(int i=2;i<=500;i++)
{
A[i]=A[i-1];
A[i]+=2*i-1;
for(int j=1;j<i;j++)
{
A[i]+=i-j;
}//朝上
for(int j=2;2*j<=i;j++)
{
A[i]+=i-2*j+1;
}//在这里出的错
}
int n;
while(scanf("%d",&n)!=EOF)
{
cout<<A[n]<<endl;
}
return 0;
}
HDU1936--Counting Triangles
最新推荐文章于 2020-02-23 09:43:57 发布