4.B

题目连接http://acm.hust.edu.cn/vjudge/contest/125308#problem/B

题目大意是N个三角形最多可以把平面分成几个部分,画图找规律。1个是2,2个是8,多6,3个是20,多12,4个是38,多18.

根据规律有 平面个数=(n-1)个三角形的平面个数+6*(n-1)。

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int t,n,sum;
    scanf("%d
",&t);
    while(t--)
    {  sum=2;
        scanf("%d",&n);
        if(n==1) printf("%d
",sum);
        else
        { for(int i=2;i<=n;i++)
                sum+=(i-1)*6;
        printf("%d
",sum);
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Twsc/p/5725266.html