sgu 135. Drawing Lines 找规律

本文探讨了通过绘制N条直线可以将无限大的纸张分割成的最大区域数量问题,并提供了一个简洁的C++代码示例来解决该问题。文章介绍了如何根据输入的直线数量计算可能的最大区域数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

135. Drawing Lines

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

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 2lines, 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



#include <bits/stdc++.h>

using namespace std;

void solve(){
    long long n;
    scanf("%lld",&n);
    printf("%lld",1+(1+n)*n/2);

}

int main(){
    solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值