ZCMU 1010 Drawing Lines

Description

Little Johnny likes to draw a lot. A few days ago he painted lots of straight lines on his sheet of paper. Then he counted in how many zones the sheet of paper was split by these lines. He noticed that this number is not always the same. For instance, if he draws 2 lines, the sheet of paper could be split into 4, 3 or even 2 (if the lines are identical) zones. Since he is a very curious kid, he would like to know which is the maximum number of zones into which he can split the sheet of paper, if he draws N lines. The sheet of paper is to be considered a very large (=infinite) rectangle.

Input

The input file will contain an integer number:T(T<=1000);

then will contain T integers :N (0<=N<=65535).

Output

You should output: the maximum number of zones into which the sheet of paper can be split if Johnny draws N lines

Sample Input

2
0
1

Sample Output

1
2
——————————————————————————————————————————————————————————————
AC代码:
#include<stdio.h>

int main()
{
  int i,T;
  double N;
  scanf("%d",&T);
  for(i=1;i<=T;i++)
  {
    scanf("%lf",&N);
    printf("%.0f\n",(N*N+N+2)/2);
  }
  return 0;
}
——————————————————————————————————————————————————————————————

解题报告:
一条线最多分平面为2部分(2=1+1)
两条线最多分平面为4部分(4=1+1+2)
三条线最多分平面为7部分(7=1+1+2+3)
四条线最多分平面为11部分(11=1+1+2+3+4)

容易通过线段交点的个数来归纳得出更加一般的结论:
n条线最多分平面为(n^2+n+2)/2个部分((n^2+n+2)/2=1+1+2+3+4+....+n)
posted @ 2013-01-17 20:04  雷克雅未克  阅读(254)  评论(0编辑  收藏  举报