码迷,mamicode.com
首页 > Windows程序 > 详细

SGU - 135 - Drawing Lines (简单数学!)

时间:2014-12-11 22:34:30      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:acm   algorithm   c++   icpc   sgu   

SGU - 135
Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u

 Status

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 43 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: N (0<=N<=65535).

Output

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

Sample Input #1

0

Sample Output #1

1

Sample Input #2

1

Sample Output #2

2

Author : Mugurel Ionut Andreica
Resource : SSU::Online Contester Fall Contest #2
Date : Fall 2002

Source



也是一个数学题,找规律的。。


规律:1,2,4,7,11,16......        a(n) = n*(n+1)/2+1;(n从0开始)


AC代码:


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", (int)((long long)n*(n+1)/2+1)); 
	return 0;
} 


SGU - 135 - Drawing Lines (简单数学!)

标签:acm   algorithm   c++   icpc   sgu   

原文地址:http://blog.csdn.net/u014355480/article/details/41872059

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!