HDU2050 折线分割平面
题目:acm.hdu.edu.cn/showproblem.php?pid=2050
递推:
从直线入手,第n条直线,最多和平面上的直线有n-1个交点,多出(n-1)+1个部分
序号 | 1 | 2 | 3 | ... | n |
交点 | 0 | 1 | 2 | ... | n-1 |
多出部分 | 1 | 2 | 3 | ... | (n-1)+1 |
总部分 2 4 7 ....
在转化为折线,当增加第n条折线时,与图形新的交点最多2*2*(n-1), 多出2*2*(n-1)+1 个部分
(可以把折线看作两条直线理解)
所以 f(n) = f(n-1) + 4*(n-1)+1;
AC代码:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define FO freopen("in.txt", "r", stdin);
#define lowbit(x) (x&-x)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int inf = 0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>
inline bool scan_d(T &ret)
{
char c; int sgn;
if (c = getchar(), c == EOF) return 0; //EOF
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
inline void out(ll x)
{
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 10010;
ll f[maxn], ans;
int main() {
int _, n;
f[1] = 2;
rep(i, 2, maxn) {
f[i] = f[i-1]+4*(i-1)+1;//递推公式
}
for(scan_d(_);_;_--) {
scan_d(n);
out(f[n]);
printf("\n");
}
}
HDU2050 折线分割平面的更多相关文章
- HDU-2050 折线分割平面 找规律&递推
题目链接:https://cn.vjudge.net/problem/HDU-2050 题意 算了吧,中文题不解释了 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线 ...
- hdu2050 折线分割平面---递推
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2050 题目大意: 求n条折线分割平面的最大数目 思路: 先看n条直线的时候 一条直线 2个平面 两条 ...
- HDU2050离散数学折线分割平面
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 折线分割平面[HDU2050]
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU2050 由直线分割平面推广到折线分割平面
直线分割平面问题: 加入已有n-1条直线,那么再增加一条直线,最多增加多少个平面? 为了使增加的平面尽可能的多,我们应该使新增加的直线与前n条直线相交,且不存在公共交点.那么我们可以将新增加的这条直线 ...
- hdoj 2050 折线分割平面
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 2050:折线分割平面(水题,递归)
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU_2050——折线分割平面问题,递推
Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可以将平面 ...
- 7C - 折线分割平面
我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示. Input ...
随机推荐
- CSS让图标变成白色或黑色实例页面 和css变灰色
css代码 .black { filter: brightness(0); } .white { filter: brightness(100); } html代码 <h4>原图</ ...
- python 标准库 —— http(http.cookiejar)
1. cookie 信息的读取 from urllib import request import http from http import cookiejar cookie = cookiejar ...
- Nhibernate 三种配置方式
1 App.config 的配置: <?xml version="1.0" encoding="utf-8" ?><configuration ...
- 系列文章--8天学通MongoDB
随笔分类 - MongoDB 8天学通MongoDB——第八天 驱动实践 摘要: 作为系列的最后一篇,得要说说C#驱动对mongodb的操作,目前驱动有两种:官方驱动和samus驱动,不过我个人还是喜 ...
- Linux环境下,开启tomcat时报transport error 202: bind failed: 地址已在使用
转载自:http://blog.csdn.net/mooncom/article/details/61913813 问题描述:今天我在Linux环境下配置tomcat,在tomcat/conf下的se ...
- HDOJ1075字典翻译(map应用)
#include<iostream> #include<cstdio> #include<map> #include<string> #include& ...
- linux日常管理-rsync后台服务方式-2
把本地的数据拷贝到远程 这里是个错误,read only.只允许读,不允许写. 改一下远程机器的配置文件 把read only改为no 拷贝到远程成功 tree一下远程机器的目录 ////////// ...
- static和final的区别
1.static是静态修饰关键字,可以修饰变量和程序块以及类方法: 当你定义一个static的变量的时候jvm会将将其分配在内存堆上,所有程序对它的引用都会指向这一个地址而不会重新分配内存: 修饰一个 ...
- javascript之模拟块级作用域
在java.C++等语言中,变量i在会在for循环的语句块中定义,循环一旦结束,变量i就会被销毁.可是在javaScript中,从定义开始,就可以在函数内部随处访问.比如 function outpu ...
- Jmeter测试接口简单使用教程
1. 打开 解决 apache-jmeter-2.13 然后进解压后的然后点击bin 文件里面的jmeter.bat 打开jmeter 2. 添加测试组件 1:添 ...