题意:

给出一个\(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;
}

最新文章

  1. STL之容器适配器priority_queue
  2. bounds的剖析
  3. memcached +mysql+php 测试例子
  4. struts checkbox选中
  5. React-用Jest测试
  6. MySQL所有函数及操作符
  7. Linux 下通过脚本实现远程自动备份
  8. JAVAEE——struts2_04:自定义拦截器、struts2标签、登陆功能和校验登陆拦截器的实现
  9. spring + springmvc+ mybatis 事务管理及控制
  10. 【CODEVS 6384 大米兔学全排列】
  11. 2.5 Cesium视域分析的实现
  12. 洛谷P3600 随机数生成器(期望dp 组合数)
  13. 使用time模块,转化时间格式
  14. 一次UNITY闪退问题的定位心得
  15. LeetCode--219--存在重复元素2
  16. java实现邮箱验证的功能
  17. Ubuntu 16.04.5安装docker
  18. hive中 udf,udaf,udtf
  19. 51Nod 1344 走格子 | 贪心
  20. Python操作MySQL+Redis+MongoDB

热门文章

  1. Webstorm 激活
  2. 前端html与css学习笔记总结篇(超详细)
  3. 解释器模式和php实现
  4. html5 新增表单控件和表单属性
  5. 织梦DeDeCMS友情链接文字显示不全
  6. 安卓中Paint类和Canvas类的方法汇总
  7. Azure 门户使用概览
  8. 利用jieba第三方库对文件进行关键字提取
  9. 关于vcpkg的一些技术细节
  10. 如何使用Python生成200个优惠券(激活码)