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;
}
相关推荐
lueluelue472 小时前
LeetCode:链表
算法·leetcode·链表
橘子汽水1684 小时前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
huameinan狮子5 小时前
Adaboost算法原理与计算实例
算法
别怪我很水5 小时前
API中提供了VelocityTracker类用于计算触摸事件MotionEvent的速度,而其内部默认使用的方法就是最小二乘法,本 ...
算法·gitee·最小二乘法
Re.不晚8 小时前
挑战做100道力扣算法- DAY1
算法·leetcode·职场和发展
蓝悦无人机8 小时前
《Planning algorithms》读书笔记——第1章 引言
算法·读书笔记·规划算法·lavalle
Sagittarius_A*8 小时前
分组密码基础(二):Feistel 结构与 DES 的设计思想
算法·信息安全·密码学·des·数论
青山木9 小时前
Hot 100 --- 搜索插入位置
java·数据结构·算法·leetcode
alexwang2119 小时前
HDU 4348 详细题解
c++·算法·题解·hdu·主席树·可持久化数据结构·可持久化线段树