Description
用N个三角形最多可以把平面分成几个区域?
Input
输入数据的第一行是一个正整数T(1<=T<=10000),表示测试数据的数量.然后是T组测试数据,每组测试数据只包含一个正整数N(1<=N<=10000).
Output
对于每组测试数据,请输出题目中要求的结果.
Sample Input
2 1 2
Sample Output
2 8
解题思路:这是一道组合排列问题,具体原理的地址:http://www.mofangge.com/html/qDetail/02/x0/201408/4hcwx0021011542.html
代码:
1 #include <cstdio> 2 #include <algorithm> 3 #include <iostream> 4 5 6 using namespace std; 7 8 int maxn[10001]; 9 10 void triangle() 11 { 12 memset(maxn,0,sizeof(maxn)); 13 maxn[1]=2; 14 for (int i=2;i<=10000;i++) 15 { 16 maxn[i]=maxn[i-1]+3*((i-1)*2);//原因:http://www.mofangge.com/html/qDetail/02/x0/201408/4hcwx0021011542.html 17 } 18 } 19 20 int main() 21 { 22 int t=0,n=0; 23 triangle(); 24 scanf("%d",&t); 25 while (t) 26 { 27 t--; 28 scanf("%d",&n); 29 printf("%d\n",maxn[n]); 30 } 31 return 0; 32 }