Time Limit: 10 second
Memory Limit: 2 MB
问题描述
同一平面内有n(n≤500)条直线,已知其中p(p≥2)条直线相交与同一点,则这n条直线最多能将平面分割成多少个不同的区域?
Input
两个整数n(n≤500)和p(2≤p≤n)。
Output
一个整数,代表最多分割成的区域数目
Sample Input
12 5
Sample Output
73
【题目链接】:http://noi.qz5z.com/viewtask.asp?id=9303
【题解】
先考虑那P条相交于一点的线;
它们会形成2*p个平面;
然后再考虑1条一条的增加线段;
设再加一条线段之前线段树为i;
则最好的情况是这条新加的线段和每条线段都相交;
这样又会多出i+1个平面来;
则有fi+1=fi+i+1;
这样就搞出递推公式了;
【完整代码】
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int n,p;
int main()
{
//freopen("F:\rush.txt","r",stdin);
rei(n);rei(p);
LL ans = 2*p;
rep1(i,p+1,n)
ans = ans+i;
cout << ans << endl;
return 0;
}