HDU 5047 Sawtooth 高精度
题意:
给出一个\(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 高精度的更多相关文章
- HDU 5047 Sawtooth(大数优化+递推公式)
http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...
- HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...
- HDU 5047 Sawtooth 找规律+拆分乘
Sawtooth Think about a plane: ● One straight line can divide a plane into two regions. ● Two lines ...
- 2014 网选 上海赛区 hdu 5047 Sawtooth
题意:求n个'M'型的折线将一个平面分成的最多的面数! 思路:我们都知道n条直线将一个平面分成的最多平面数是 An = An-1 + n+1 也就是f(n) = (n*n + n +2)/2 对于一个 ...
- HDU 5047
http://acm.hdu.edu.cn/showproblem.php?pid=5047 直到看到题解,我才知道这道题考的是什么 首先交点数是Σ(16*i),区域区分的公式是 边数+点数+1=分成 ...
- Hdu 5568 sequence2 高精度 dp
sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...
- hdu 1042 N!(高精度乘法 + 缩进)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...
- hdu 5047 大数找规律
http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...
- HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)
Sum Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status ...
随机推荐
- h5复制粘贴板,打开APP功能
<div class="container"> <img src="../themes/mall/img/i_red_ad4.jpg"> ...
- gulp管理angular2项目 配置文件
目录结构: projectName |_ src |_ app |_ index.html |_ main.ts |_ systemjs.config.js |_ gulpfile.js |_ pac ...
- html5响应式
(function (doc, win) { var docEl = doc.documentElement, resizeEvt = ‘orientationchange’ in window ? ...
- PHP的socket通信原理及实现
对TCP/IP.UDP.Socket编程这些词你不会很陌生吧?随着网络技术的发展,这些词充斥着我们的耳朵.那么我想问: 1. 什么是TCP/IP.UDP?2. Sock ...
- LINQ 组合查询 和分页查询的使用
前端代码 <%@ Page Language="C#" AutoEventWireup="true" Debug="true" Cod ...
- CF 55D Beautiful numbers (数位DP)
题意: 如果一个正整数能被其所有位上的数字整除,则称其为Beautiful number,问区间[L,R]共有多少个Beautiful number?(1<=L<=R<=9*1018 ...
- IIS 7.0的根文件(applicationHost.config)位置及说明
位置 C:\Windows\System32\inetsrv\config\applicationHost.config 说明 https://www.microsoft.com/taiwan/tec ...
- 用python写trojan的过程中遇到的各种问题
由于之前已经conn, addr = s.accept() 所以改为 conn.recv spyder无法同时运行client 和 server 分别在spyder和anaconda prompt运 ...
- [转]C++中sizeof(struct)怎么计算?
版权属于原作者,我只是排版. 1. sizeof应用在结构上的情况 请看下面的结构: struct MyStruct{ double dda1; char dda; int type;}; 对结构My ...
- 2018.4.9 Ubuntu install kreogist-mu
先下载kreogist m文件 然后在下载哪里右键点击打开终端 输入sudo dpkg -i + 文件名 输入密码 下一步会显示 未安装未安装软件包 libmpv1. jiexialai要处理 sud ...