题意:

给出一个\(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. BeanCopier使用说明

    BeanCopier从名字可以看出了,是一个快捷的bean类复制工具类. 一 如何使用,我就直接丢代码了 public class BeanCopierTest { static SimpleDate ...

  2. hubbledotnet 使用笔记

    Hubble vs 字符串 <connectionStrings> <add name="Search" connectionString="serve ...

  3. go日志输入到es

    1.依赖 github.com/alecthomas/log4go 2.配置 <filter enabled="true"><!-- enabled=false ...

  4. 通过Maven构建打包Spring boot,并将config配置文件提取到jar文件外

    如果通过不同的IDE打包,着实会觉得依赖性太大,并且容易出现错误,操作也比较复杂 同时,spring-boot-maven-plugin的使用感觉,相关配置太少,并且无法满足方便部署和运行的需求. 这 ...

  5. Python+selenium 之操作Cookie

    在验证浏览器中cookie是否正确时,有时基于真实cookie的测试是无法通过白盒和集成测试进行的.Webdriver提供了操作Cookie的相关方法,可以读取,添加和删除cookie信息. 文本we ...

  6. Python+selenium之键盘事件

    keuys()类提供键盘上所有的按键方法.send_keys()方法可以用来模拟键盘输入. from selenium import webdriver from selenium.webdriver ...

  7. python 之网页解析器

    一.什么是网页解析器 1.网页解析器名词解释 首先让我们来了解下,什么是网页解析器,简单的说就是用来解析html网页的工具,准确的说:它是一个HTML网页信息提取工具,就是从html网页中解析提取出“ ...

  8. pc端常见布局---水平居中布局 单元素不定宽度

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. UVA 10037 Bridge (基础DP)

    题意: 过河模型:有n个人要渡河,每个人渡河所耗时可能不同,只有1只船且只能2人/船,船速取决于速度慢的人.问最少耗时多少才能都渡完河? 思路: n<2的情况比较简单. 考虑n>2的情况, ...

  10. EF生成的实体映射含义

    如图: 组合效果: LEFT JOIN 效果: this.HasOptional(t => t.子表) .WithMany(t => t.主表) .HasForeignKey(d => ...