A : 平面划分

Description

一条直线可以把平面分成两部分,两条直线分成四部分。那么 n 条直线最多可以把平面分成几部分?

Input

多组数据,每组数据一个正整数 1≤�≤1000。

Output

Sample

#0
Input

Copy

复制代码
3
5
Output

Copy

复制代码
7
16

Hint

小学奥数:要分的最多,就需要两两相交,且没有任何三条直线交于一点。假设已有 n 条直线,在增加第 n+1 条时,与之前每条直线都有一个独立交点, n 个交点把新的直线分成 n+1 段,每段都会把一个部分一分为二,所以增加了 n+1 块。

复制代码
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include "stdio.h"
#include <vector>
using namespace std;
// 1 2
// 2 4
// 3 7
// 4 11
// 5 16
int a[1005];
int main()
{
    int n;
    a[1] = 2;
    a[2] = 4;
    for (int i = 3; i <= 1005; i++)
    {
        a[i] = a[i - 1] + i;
    }
    while (cin >> n)
    {
        cout << a[n] << endl;
    }
    return 0;
}
相关推荐
xiaoxue..2 分钟前
二叉搜索树 BST 三板斧:查、插、删的底层逻辑
javascript·数据结构·算法·面试
蒙奇D索大3 分钟前
【数据结构】排序算法精讲 | 快速排序全解:分治思想、核心步骤与示例演示
数据结构·笔记·学习·考研·算法·排序算法·改行学it
YGGP6 分钟前
【Golang】LeetCode 55. 跳跃游戏
算法·leetcode
练习时长一年2 小时前
Leetcode热题100(跳跃游戏 II)
算法·leetcode·游戏
小白菜又菜8 小时前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
wuhen_n9 小时前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo9 小时前
leetcode 2483
数据结构·算法·leetcode
Xの哲學10 小时前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
大头流矢10 小时前
归并排序与计数排序详解
数据结构·算法·排序算法
油泼辣子多加10 小时前
【信创】算法开发适配
人工智能·深度学习·算法·机器学习