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 ...
随机推荐
- MongoDB 最初级步骤
对库TEST下的LOG聚集集合中的inserttim字段加索引 步骤(注意:前四步步骤不能错,错了不行): 一,打开F:\mongodb\bin\mongo.exe,也可以用cmd命令指到这个exe执 ...
- This file's format is not supported or you don't specify a correct format. 解决办法
string path = @"c:\请假统计表.xlsx"; Workbook workBook = new Workbook(); workBook.Open(path); A ...
- java获取服务器一些信息的方法
request.getServletContext().getRealPath("/") 获取项目所在服务器的全路径,如:D:\Program Files\apache-tomca ...
- (六)我的JavaScript系列:更好的JavaScript之CoffeeScript
世界上的很多天才都在为构建更好的JavaScript而努力.已经有了很多尝试,其中最有前途的,无非就是CoffeeScript和TypeScript了.面对CoffeeScript,我有一见如故的感觉 ...
- 如何从桌面程序向浏览器传递cookie或自定义header
类似问题 从c#程序启动ie并传递cookie 打开默认浏览器并传递cookie 打开一个web浏览器使用c#应用程序并添加请求头 猜想 从wpf程序打开默认浏览器并定位到一个url ,并且向这个ur ...
- 【转】iOS开发里的Bundle是个啥玩意?!
初学iOS开发的同学,不管是自己写的,还是粘贴的代码,或多或少都写过下面的代码 [[NSBundle mainBundle] pathForResource:@"someFileName&q ...
- ACM博弈论基础
博弈论的题目有如下特点: 有两名选手 两名选手交替操作,每次一步,每步都在有限的合法集合中选取一种进行 在任何情况下,合法操作只取决于情况本身,与选手无关 游戏败北的条件为:当某位选手需要进行操作时, ...
- Asp.Net Core 进阶(四)—— 过滤器 Filters
一.介绍 Asp.Net Core Filter 使得可以在请求处理管道的特定阶段的前后执行代码,我们可以创建自定义的 filter 用于处理横切关注点. 横切关注点的示例包括错误处理.缓存.配置.授 ...
- 2018.5.4 AndroidStudio遇到的问题
新建项目初出现异常报错 Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict 发生这类型的错误, ...
- sum特殊用法
在python中,list可以存储False和True a = [False] python的sum除了可以加数字,还可以计算列表中False,True的个数,默认是计算False个数 >> ...