日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【9303】平面分割

發布時間:2023/11/30 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 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; }

轉載于:https://www.cnblogs.com/AWCXV/p/7626899.html

總結

以上是生活随笔為你收集整理的【9303】平面分割的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。