【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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391221.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391221.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391221.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

簡述yolo1-yolo3_使用YOLO框架進行對象檢測的綜合指南-第一部分

簡述yolo1-yolo3重點 (Top highlight)目錄&#xff1a; (Table Of Contents:) Introduction 介紹 Why YOLO? 為什么選擇YOLO&#xff1f; How does it work? 它是如何工作的&#xff1f; Intersection over Union (IoU) 聯合路口(IoU) Non-max suppression 非最大抑制 Networ…

django:資源網站匯總

Django REST framework官網 http://www.sinodocs.cn/ django中文網 https://www.django.cn/ 轉載于:https://www.cnblogs.com/gcgc/p/11542068.html

Kubernetes 入門(4)集群配置

1. 集群配置 報錯&#xff1a; message: ‘runtime network not ready: NetworkReadyfalse reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized’ 原因&#xff1a;cni未被初始化&#xff08;CNI 是 Container Network In…

【例9.8】合唱隊形

【例9.8】合唱隊形 鏈接&#xff1a;http://ybt.ssoier.cn:8088/problem_show.php?pid1264 時間限制: 1000 ms 內存限制: 65536 KB【題目描述】 N位同學站成一排&#xff0c;音樂老師要請其中的(N-K)位同學出列&#xff0c;使得剩下的K位同學排成合唱隊形。 合唱隊形是…

scrum流程 規劃 沖刺_Scrum –困難的部分2:更快地沖刺

scrum流程 規劃 沖刺In the first part, I presented my favorite list of Scrums hard parts and how to work around them. In the second part, I offer you a colorful bouquet of workarounds as well. Have fun!在第一部分中 &#xff0c;我介紹了我最喜歡的Scrum困難部分…

JAVA基礎知識|lambda與stream

lambda與stream是java8中比較重要兩個新特性&#xff0c;lambda表達式采用一種簡潔的語法定義代碼塊&#xff0c;允許我們將行為傳遞到函數中。之前我們想將行為傳遞到函數中&#xff0c;僅有的選擇是使用匿名內部類&#xff0c;現在我們可以使用lambda表達式替代匿名內部類。在…

數據庫:存儲過程_數據科學過程:摘要

數據庫:存儲過程Once you begin studying data science, you will hear something called ‘data science process’. This expression refers to a five stage process that usually data scientists perform when working on a project. In this post I will walk through ea…

901

901 轉載于:https://www.cnblogs.com/Forever77/p/11542129.html

leetcode 137. 只出現一次的數字 II(位運算)

給你一個整數數組 nums &#xff0c;除某個元素僅出現 一次 外&#xff0c;其余每個元素都恰出現 三次 。請你找出并返回那個只出現了一次的元素。 示例 1&#xff1a; 輸入&#xff1a;nums [2,2,3,2] 輸出&#xff1a;3 示例 2&#xff1a; 輸入&#xff1a;nums [0,1,0,…

【p081】ISBN號碼

Time Limit: 1 second Memory Limit: 50 MB 【問題描述】 每一本正式出版的圖書都有一個ISBN號碼與之對應&#xff0c;ISBN碼包括9位數字、1位識別碼和3位分隔符&#xff0c;其規定格式如“x-xxx-xxxxx-x”&#xff0c;其中符號“-”是分隔符&#xff08;鍵盤上的減號&#xff…

gitlab bash_如何編寫Bash一線式以克隆和管理GitHub和GitLab存儲庫

gitlab bashFew things are more satisfying to me than one elegant line of Bash that automates hours of tedious work. 沒有什么比讓Bash自動完成數小時繁瑣工作的Bash優雅系列令我滿意的了。 As part of some recent explorations into automatically re-creating my la…

寒假學習筆記(4)

2018.2.11 類中的常成員 關鍵字const&#xff0c;在類定義中聲明數據成員使用關鍵字限定&#xff0c;聲明時不能初始化。初始化列表&#xff0c;類中的任何函數都不能對常數據成員賦值&#xff0c;包括構造函數。為構造函數添加初始化列表是對常數據成員進行初始化的唯一途徑。…

svm和k-最近鄰_使用K最近鄰的電影推薦和評級預測

svm和k-最近鄰Recommendation systems are becoming increasingly important in today’s hectic world. People are always in the lookout for products/services that are best suited for them. Therefore, the recommendation systems are important as they help them ma…

Oracle:時間字段模糊查詢

需要查詢某一天的數據&#xff0c;但是庫里面存的是下圖date類型 將Oracle中時間字段轉化成字符串&#xff0c;然后進行字符串模糊查詢 select * from CAINIAO_MONITOR_MSG t WHERE to_char(t.CREATE_TIME,yyyy-MM-dd) like 2019-09-12 轉載于:https://www.cnblogs.com/gcgc/p/…

cogs2109 [NOIP2015] 運輸計劃

cogs2109 [NOIP2015] 運輸計劃 二分答案樹上差分。 STO鏈剖巨佬們我不會&#xff08;太虛偽了吧 首先二分一個答案&#xff0c;下界為0,上界為max{路徑長度}。 然后判斷一個答案是否可行&#xff0c;這里用到樹上差分。 &#xff08;闊以理解為前綴和&#xff1f;&#xff1f;&…

leetcode 690. 員工的重要性(dfs)

給定一個保存員工信息的數據結構&#xff0c;它包含了員工 唯一的 id &#xff0c;重要度 和 直系下屬的 id 。 比如&#xff0c;員工 1 是員工 2 的領導&#xff0c;員工 2 是員工 3 的領導。他們相應的重要度為 15 , 10 , 5 。那么員工 1 的數據結構是 [1, 15, [2]] &#x…

組件分頁_如何創建分頁組件

組件分頁The theme for week #17 of the Weekly Coding Challenge is:每周編碼挑戰第17周的主題是&#xff1a; 分頁 (Pagination) A Pagination Component is used on websites where you have more content available than you want to display at one time to the user so …

web-項目管理

總結 目的是 1.可查詢 2.方便團隊管理 每個成員都可以看到任何東西 項目 需求 計劃 bug 按模板來 1.問題描述 2.原因分析 3.解決方法 開發 提交代碼 按模板來 1.問題描述 2.原因分析 3.解決方法 打包 更新說明文件.txt 按模板來 一、更新說明 1.問題描述 1&#xff09;計劃號 2…

cnn對網絡數據預處理_CNN中的數據預處理和網絡構建

cnn對網絡數據預處理In this article, we will go through the end-to-end pipeline of training convolution neural networks, i.e. organizing the data into directories, preprocessing, data augmentation, model building, etc.在本文中&#xff0c;我們將遍歷訓練卷積神…

leetcode 554. 磚墻

你的面前有一堵矩形的、由 n 行磚塊組成的磚墻。這些磚塊高度相同&#xff08;也就是一個單位高&#xff09;但是寬度不同。每一行磚塊的寬度之和應該相等。 你現在要畫一條 自頂向下 的、穿過 最少 磚塊的垂線。如果你畫的線只是從磚塊的邊緣經過&#xff0c;就不算穿過這塊磚…