生活随笔
收集整理的這篇文章主要介紹了
【9303】平面分割
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 secondtypedef 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 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()
{rei(n);rei(p);LL ans =
2*p;rep1(i,p+
1,n)ans = ans+i;
cout << ans << endl;
return 0;
}
轉載于:https://www.cnblogs.com/AWCXV/p/7626899.html
總結
以上是生活随笔為你收集整理的【9303】平面分割的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。