Recurrence of a triangle (hdu1249) and a triangle hdu1249
Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 5598 Accepted Submission (s): 3816
Problem Description how many areas can a plane be divided into with N triangles at most?
The first line of Input data is a positive integer T (1 <= T <= 10000), indicating the number of test data. then there is the T group of test data, each group of test data contains only one positive integer N (1 <= N <= 10000 ).
Output for each group of test data, please Output the results required in the question.
Sample Input212
Sample Output28 train of thought: You can figure it yourself. The rule I found is: each edge of each newly added triangle overlaps two existing sides of each triangle. [(n-1) * 2-1] * 3 + 3 = 6 * (n-1) reprinted please indicate the source: Looking for and star child questions link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1249
#include<stdio.h>#define LL __int64LL ans[10005];void init(){ ans[0]=1; ans[1]=2; ans[2]=8; for(int i=3;i<=10000;i++) { //(2*(n-1)-1)*3+3=6*(n-1) ans[i]=ans[i-1]+6*(i-1); }}int main(){ int n,T; init(); scanf("%d",&T); while(T--) { scanf("%d",&n); printf("%I64d\n",ans[n]); } return 0;}