【9303】平面分割
来源:互联网 发布:c和java哪个好就业 编辑:程序博客网 时间:2024/05/01 19:08
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;}
0 0
- 【9303】平面分割
- 分割平面
- 平面分割
- 平面分割
- 平面分割
- 平面分割
- 分割平面,平面分割空间问题
- 直线分割平面、分割空间
- 2050 折线分割平面
- HDU2050折线分割平面
- 折线分割平面问题
- 分割平面问题
- 折线分割平面
- HDOJ2050 折线分割平面
- hdu2050 折线分割平面
- 平面分割问题
- 折线分割平面
- 折线分割平面
- Qwidget透明相关(仅一点点)附代码及运行结果
- 矩阵求和
- 7个鲜为人知的编程真相
- 一个简单的用户登录界面
- C语言实验——数组逆序
- 【9303】平面分割
- 润乾报表内存溢出的排查步骤与解决建议
- 拆手机
- SPI引脚的配置
- 多个电脑之间使用相同的ssh密钥
- 计算机视觉三大国际会议:ICCV, CVPR,ECCV
- Android studio 插件
- 第十四周数组逆序
- 输入一个数插入有序数组中