平面分割

来源:互联网 发布:js里取juid 编辑:程序博客网 时间:2024/04/29 09:23

平面分割
描述 Description
【问题描述】
  同一平面内有n(n≤500)条直线,已知其中p(p≥2)条直线相交于同一点,则这n条直线最多能将平面分割成多少个不同的区域?
【输入格式】
  两个整数n(n≤500)和p(2≤p≤n)。
【输出格式】
  一个正整数,代表最多分割成的区域数目。
【输入样例】Surface.in
  12 5
【输出样例】Surface.out
  73

时间限制 Time Limitation
各个测试点1s

这里写图片描述
如图,首先考虑n-1=p(n,p>=2)的情况。此时分割的空间数为2(n-1)。

再加上一条直线。
这里写图片描述
此时直线每过一条直线,就能多分割出一块空间,共可分割出n块。

所以得到递推式:f(p)=2*p;
f(n)=f(n-1)+n;

#include<iostream>using namespace std;int main(){    int n,m;    cin>>n>>m;    int total=2*m;    for (int i=m+1;i<=n;i++)    total+=i;    cout<<total;}
0 0
原创粉丝点击