(hdu step 2.2.5)三角形(求n个三角形能把平面分成多少部分)

题目:

三角形

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 653 Accepted Submission(s): 493
 

Problem Description

用N个三角形最多可以把平面分成几个区域?


Input

输入数据的第一行是一个正整数T(1<=T<=10000),表示测试数据的数量.然后是T组测试数据,每组测试数据只包含一个正整数N(1<=N<=10000).


Output

对于每组测试数据,请输出题目中要求的结果.


Sample Input

2
1
2


Sample Output

2
8


Author

Ignatius.L

 

Recommend

Ignatius.L

题目分析:

数学题。递推公式是:ans[i] = ans[i-1] + 6*(i-1).推导过程如下:

平面本身是1部分.一个三角形将平面分成三角形内、外2部分,即增加了1部分,
两个三角形不相交时将平面分成3部分,相交时,交点越多分成的部分越多(见下图);

由上图看出,新增加的部分数与增加的交点数相同,所以,再画第3个三角形时,应使每条边的交点尽量多;
对于每个三角形,因为1条直线最多与三角形的两条边相交,所以第3个三角形的每条边最多与前面2个三角形的各两条边相交,共可产生3×(2×2)=12(个)交点,即增加12部分;
因此,3个三角形最多可以把平面分成:1+1+6+12=20(部分);
由上面的分析,当画第n(n≥2)个三角形时,每条边最多与前面已画的(n-1)个三角形的各两条边相交,
共可产生交点:3×[(n-l)×2]=6(n-1)(个),能新增加6(n-1)部分,
因为1个三角形时有2部分,所以n个三角形最多将平面分成的部分数是:
2+6×[1+2+…+(n-1)]=2+6×

n(n-1)
2

=2+3n(n-1),
当n=10时,可分成:2+3×10×(10-1)=272(部分).
答:3个三角形最多可以把平面分成20部分,10个三角形最多可以把平面分成272部分.

代码如下:

/*
 * d.cpp
 *
 *  Created on: 2015年2月2日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>

using namespace std;

const int maxn = 10005;

int a[maxn];

/**
 * 求n个三角形能把平面分成几块
 * a[i]:是i个三角形能把平面分成的个数
 */
void init(){
	a[1] = 2;
	int i;
	for(i = 2 ; i < maxn ; ++i){
		a[i] = a[i-1] + 6*(i-1);
	}
}

int main(){
	init();

	int t;;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		printf("%d\n",a[n]);
	}

	return 0;
}
时间: 2024-10-02 01:52:58

(hdu step 2.2.5)三角形(求n个三角形能把平面分成多少部分)的相关文章

(hdu step 4.2.3)Rescue(求从起点到终点的最少步数,遇到特殊节点需要耗时2秒)

题目: Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 924 Accepted Submission(s): 387   Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is des

(hdu step 7.1.7)Wall(求凸包的周长——求将全部点围起来的最小凸多边形的周长)

题目: Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119 Accepted Submission(s): 47   Problem Description Once upon a time there was a greedy King who ordered his chief Architect to build a wa

(hdu step 6.1.8)Pseudoforest(求有一个环的最大生成树)

题目: Pseudoforest Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 283 Accepted Submission(s): 122   Problem Description In graph theory, a pseudoforest is an undirected graph in which every connec

(hdu step 2.2.1)Fibonacci(求当n很大时的斐波那契数)

题目: Fibonacci Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3036 Accepted Submission(s): 1397   Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] =

(hdu step 1.3.1)FatMouse&#39; Trade(在收入需要一定的付出的情况下求最大收入)

题目: FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5092 Accepted Submission(s): 1530   Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats gua

(hdu step 6.1.2)Eddy&#39;s picture(在只给出二维坐标点的情况下,求让n个点连通的最小费用)

题目: Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 172 Accepted Submission(s): 126   Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be

(hdu step 3.2.4)FatMouse&#39;s Speed(在第一关键字升序的情况下,根据第二关键字来求最长下降子序列)

在写题解之前给自己打一下广告哈~..抱歉了,希望大家多多支持我在CSDN的视频课程,地址如下: http://edu.csdn.net/course/detail/209 题目: FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1034 Accepted Submission(s): 526   Proble

(hdu step 3.1.5)Tiling_easy version(求用2*1、2*2两种骨格铺满2*n的网格的方案数)

在写题解之前给自己打一下广告哈~..抱歉了,希望大家多多支持我在CSDN的视频课程,地址如下: http://edu.csdn.net/course/detail/209 题目: Tiling_easy version Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 515 Accepted Submission(s): 447   Prob

hdu 1536 S-Nim 博弈论,,求出SG&#39;函数就可以解决

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4975    Accepted Submission(s): 2141 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now