题意:略。

析:多写几个就找到规律了,第1条是2,2条时是7个,3条时是16,4条时是29,。。。。

那么规律就出来了2 * n * n + 1 - n;

也可以递推,第n条折线的两条边都与前n-1条折线的所有边都不平行,因为他们都是相交的;第n条折线的第一条边要与前n-1条折线的2*(n-1)条边都相交,

每与两个边相交就增加一个分割开的部分,所以有2*(n-1)-1个被分割的部分在这里被增加,另外一条第n条折线的边也增加2*(n-1)-1个部分,另外最后第n第折线的两边,

还要向外无限延伸,与它们相交的最后一个前n-1个折线中的边与其分别构成了一个多余的部分,而第n条折线的头部也是一个独立的部分,所 以2*(n-1)-1再+3,

就是比n-1条折线分割成的部分多出的部分数,所以有:a[n]=(2*(n-1)-1)*2+3+a[n-1];

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
const int maxn = 10000 + 5; int main(){
int T, n, a, b; cin >> T; while(T--){
scanf("%d", &n);
printf("%d\n", 2*n*n-n+1);
}
return 0;
}
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e4 + 5;
const int mod = 1e9 + 7;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL ans[maxn]; void init(){
ans[0] = 1;
for(int i = 1; i <= 10000; ++i)
ans[i] = ans[i-1] + 2LL * (2LL*(i-1)-1LL) + 3;
} LL f(int n){
if(!n) return 1;
return 2LL*(2LL*(n-1)-1LL) + 3 + f(n-1);
} int main(){
//init();
int T; cin >> T;
while(T--) cin >> n, cout << f(n) << endl;
return 0;
}

HDU 2050 折线分割平面 (递推)的更多相关文章

  1. hdu 2050 折线分割平面 (递推)

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  2. hdu 2050 折线分割平面 dp递推 *

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. hdu 2050:折线分割平面(水题,递归)

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. hdu2050 折线分割平面---递推

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2050 题目大意: 求n条折线分割平面的最大数目 思路: 先看n条直线的时候 一条直线 2个平面 两条 ...

  5. HDU 2050 折线分割平面 (数学)

    题目链接 Problem Description我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可 ...

  6. HDU 2050 折线分割平面(转)

    折线分割平面 http://acm.hdu.edu.cn/showproblem.php?pid=2050 Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微 ...

  7. HDU - 2050 - 折线分割平面(数学 + dp)

    题意: 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分 思路: 记住结论.. ...

  8. hdu 2050 折线分割平面(递推公式)

    折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. hdu 2050 折线分割平面

    训练递推用题,第一次做这个题,蒙的,而且对了. #include <stdio.h> int main(void) { int c,a; scanf("%d",& ...

随机推荐

  1. next_permutation()函数 和 prev_permutation() 按字典序求全排列

    next_permutation功能:    求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm> 与之完全相反的函数还有prev_permutation 这个 ...

  2. PL/SQL database character set(AL32UTF8) and Client character set(ZHS16GBK) are different 2012-04-11 13:01

    启动PL/SQL Developer 报字符编码不一致错误 Database character set (AL32UTF8) and Client character set (ZHS16GBK) ...

  3. uva10820Send a Table

    筛法. 首先使cnt[i]=sqr(n/i),这样cnt[i]就表示gcd(x,y)大于等于i的数对的个数,然后倒序枚举减去gcd大于i的个数就可以得到ans[i].最终得到ans[1]. 这个算法单 ...

  4. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  5. jquery live hover绑定方法

    $(".select_item span").live({ mouseenter: function() { $(this).addClass("hover") ...

  6. 给你一个承诺 - 玩转 AngularJS 的 Promise(转)

    在谈论Promise之前我们要了解一下一些额外的知识:我们知道JavaScript语言的执行环境是“单线程”,所谓单线程,就是一次只能够执行一个任务,如果有多个任务的话就要排队,前面一个任务完成后才可 ...

  7. hdu 3535 AreYouBusy

    // 混合背包// xiaoA想尽量多花时间做ACM,但老板要求他在T时间内做完n堆工作,每个工作耗时ac[i][j],// 幸福感ag[i][j],每堆工作有m[i]个工作,每堆工作都有一个性质,/ ...

  8. 在web.config里使用configSource分隔各类配置

    转:http://www.yongfa365.com/Item/using-configSource-Split-Configs.html 大型项目中,可能有多个Service,也就是会有一堆配置,而 ...

  9. ECshop 每个数据库表结构说明

    ecs_account_log // 用户账目日志表 ecs_activity // 活动表(代码,名称,开始,结束,描述) ecs_ad // 广告表(位置,类型,名称,链接,图片,开始,结束,广告 ...

  10. HDU 5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...