题意:

给出一个\(n(0 \leq n \leq 10^{12})\),问\(n\)个\(M\)形的折线最多可以把平面分成几部分。

分析:

很容易猜出来这种公式一定的关于\(n\)的一个二次多项式。

不妨设\(f(n)=an^2+bn+c\)。

结合样例我们可以列出\(3\)个方程:

\(f(0)=1,f(1)=2,f(2)=19\)

解出三个系数\(a,b,c\),然后用高精度做即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long LL; const LL MOD = 1000000000; struct Big
{
LL a[5]; Big() { memset(a, 0, sizeof(a)); } Big(LL x) { memset(a, 0, sizeof(a)); a[1] = x / MOD; a[0] = x % MOD; } void read() {
memset(a, 0, sizeof(a));
LL x; scanf("%lld", &x);
a[0] = x % MOD; a[1] = x / MOD;
} Big operator + (const Big& t) const {
Big ans;
for(int i = 0; i < 5; i++) ans.a[i] = a[i];
for(int i = 0; i < 5; i++) {
ans.a[i] += t.a[i];
int j = i;
while(ans.a[j] >= MOD) {
ans.a[j + 1] += ans.a[j] / MOD;
ans.a[j++] %= MOD;
}
}
return ans;
} Big operator * (const Big& t) const {
Big ans;
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 5; j++) if(i + j < 5) {
ans.a[i + j] += a[j] * t.a[i];
int k = i + j;
while(ans.a[k] >= MOD) {
ans.a[k + 1] += ans.a[k] / MOD;
ans.a[k++] %= MOD;
}
}
}
return ans;
} Big operator - (const Big& t) const {
Big ans;
for(int i = 0; i < 5; i++) ans.a[i] = a[i];
for(int i = 0; i < 5; i++) {
int j = i + 1;
if(ans.a[i] < t.a[i]) {
while(!ans.a[j]) j++;
ans.a[j]--;
for(int k = j - 1; k > i; k--) ans.a[k] += MOD - 1;
ans.a[i] += MOD;
}
ans.a[i] -= t.a[i];
}
return ans;
} void output() {
int i = 0;
for(i = 4; i; i--) if(a[i]) break;
printf("%lld", a[i]);
for(int j = i - 1; j >= 0; j--) printf("%09lld", a[j]);
printf("\n");
}
}; int main()
{
int T; scanf("%d", &T);
for(int kase = 1; kase <= T; kase++) {
printf("Case #%d: ", kase);
Big x; x.read();
Big ans(1);
ans = ans + (Big(8) * x * x);
ans = ans - (Big(7) * x);
ans.output();
} return 0;
}

HDU 5047 Sawtooth 高精度的更多相关文章

  1. HDU 5047 Sawtooth(大数优化+递推公式)

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...

  2. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  3. HDU 5047 Sawtooth 找规律+拆分乘

      Sawtooth Think about a plane: ● One straight line can divide a plane into two regions. ● Two lines ...

  4. 2014 网选 上海赛区 hdu 5047 Sawtooth

    题意:求n个'M'型的折线将一个平面分成的最多的面数! 思路:我们都知道n条直线将一个平面分成的最多平面数是 An = An-1 + n+1 也就是f(n) = (n*n + n +2)/2 对于一个 ...

  5. HDU 5047

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 直到看到题解,我才知道这道题考的是什么 首先交点数是Σ(16*i),区域区分的公式是 边数+点数+1=分成 ...

  6. Hdu 5568 sequence2 高精度 dp

    sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...

  7. hdu 1042 N!(高精度乘法 + 缩进)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...

  8. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  9. HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)

    Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status  ...

随机推荐

  1. SQL SERVER 同一个表并且是同一个时间字段进行相减

    表AID NUM TIEM1 10 2012-06-10 10:10:002 20 2012-06-10 20:10:003 20 2012-06-10 20:10:004 10 2012-06-10 ...

  2. 前端js优化方案(二)持续更新

    由于上篇篇幅过长,导致编辑出了问题,另开一篇文章继续: (4)减少迭代次数,最广为人知的一种限制循环迭代次数的模式被称为“达夫设备(Duff`s Device)” Duff`s Device的理念是: ...

  3. JS计算24节气的方法

    function getjq(yyyy,mm,dd){ mm = mm-1; var sTermInfo = new Array(0,21208,42467,63836,85337,107014,12 ...

  4. 《Ionic 2 实例开发》发布

    Ionic 2系列教程集结成册,在百度阅读上架发布,名为<Ionic 2实例开发>(点击书名将打开地址:http://yuedu.baidu.com/ebook/ba1bca51e4189 ...

  5. 2017.10.4 QBXT 模拟赛

    题目链接 T1 维护一个单调栈 #include <iostream> #include <cstdio> #define N 500000 #define rep(a,b,c ...

  6. Linux下解压ZIP压缩包乱码问题

    并不是所有ZIP文件都是乱码的而且导致解压失败,只有windows下压缩的ZIP在Linux中会出现这种情况.这是因为Windows和Linux下用的字符编码不同.Windows下的编码格式为GBK, ...

  7. Unity runtime性能分析器

    一. Profiler: 1. CPU Usage A. WaitForTargetFPS: Vsync(垂直同步)功能所,即显示当前帧的CPU等待时间 B. Overhead: Profiler总体 ...

  8. bzoj3209:3209: 花神的数论题

    觉得还是数位dp的那种解题形式但是没有认真的想,一下子就看题解.其实还是设置状态转移.一定要多思考啊f[i][j]=f[i-1][j]+g[i-1][j] g[i][j]=f[i-1][j-1]+g[ ...

  9. Android(java)学习笔记111:Java异常分类

    Java异常可分为3种: (1)编译时异常:Java.lang.Exception (2)运行期异常:Java.lang.RuntimeException (3)错误:Java.lang.Error

  10. Oracle中ROWID详解

    oracle数据库的表中的每一行数据都有一个唯一的标识符,或者称为rowid,在oracle内部通常就是使用它来访问数据的.rowid需要 10个字节的存储空间,并用18个字符来显示.该值表明了该行在 ...