hdu 2050 折线分割平面 递推

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2050

递推求解 参考大佬博客:https://blog.csdn.net/hpulw/article/details/50579567

 

 

#include <bits/stdc++.h>
using namespace std;
/* hdu 2050 折线分割 
  递推  可以先从直线入手分析,然后在考虑折线的情况
  直线:第 n 条线最多和前面有n - 1 个交点,也就最多增加 (n-1)+1 个部分。
  折线:可以先画一条,然后在画第二条线,最后由于是折线,有一端不在延伸出去,所以增加部分 -2  
  https://blog.csdn.net/hpulw/article/details/50579567 
  f[n]  = f[n-1] + 2*(2*(n-1)+1)+1-2; 
*/

long long f[10002];

int main ()
{
  int T;
  int a;
  //预打表
  f[1] = 2;
  for (int i=2;i<=10001;++i)
  { 
    f[i]  = f[i-1] + 2*(2*(i-1)+1)-1; 
  } 
  
  cin >> T;
  while(T--)
  {
      cin >> a;
    cout <<f[a]<<endl; 
  }    
    
  return 0;
}

 

posted @ 2018-04-14 12:40  雨落洛  阅读(129)  评论(0编辑  收藏  举报