Recurrence of a triangle (hdu1249) and a triangle hdu1249

Source: Internet
Author: User

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;}

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.