sgu 135 Drawing Lines

39 篇文章 0 订阅
18 篇文章 0 订阅

题目描述:


135. Drawing Lines

time limit per test: 0.5 sec.
memory limit per test: 4096 KB

Little Johnny likesto draw a lot. A few days ago he painted lots of straight lines on hissheet of paper. Then he counted in how many zones the sheet of paper wassplit 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 splitinto 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 maximumnumber of zones into which he can split the sheet of paper, if he drawsNlines. The sheet of paper is to be considered a very large (=infinite)rectangle.

Input

The input file willcontain an integer number: N (0<=N<=65535).

Output

You should outputone integer: the maximum number of zones into which the sheet of papercan be split if Johnny drawsN lines.

Sample Input #1

0

Sample Output #1

1

Sample Input #2

1

Sample Output #2

2

题目大意就是问n条直线最多将平面划分成多少区域?、

很容易知道就是 n*(n+1)/2+1嘛;

这估计是目前除a+b外最easy的题了。


但是。。。。。

还是要吐槽,我多Case输入居然给我PE on 1 .。。

无奈。。。

代码嘛,还是留念一个:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
#include<cstdlib>

#define inf 0xfffffff
#define CLR(a,b) memset((a),(b),sizeof((a)))
#define FOR(a,b) for(int a=1;a<=(b);(a)++)

using namespace std;
int const nMax = 1000;
int const base = 10;
typedef long long LL;
typedef pair<LL,LL> pij;

LL n;
int main(){
    cin>>n;cout<<n*(n+1)/2+1<<endl;
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值