HDU 1250 Hat's Fibonacci(高精度)
题目大意:看题。
思路:高精度
代码(671MS):
//模板测试
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; const int MAXN = ; struct bign {
int len, s[MAXN]; bign () {
memset(s, , sizeof(s));
len = ;
}
bign (int num) { *this = num; }
bign (const char *num) { *this = num; } bign operator = (const int num) {//数字
char s[MAXN];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num) {//字符串
for(int i = ; num[i] == ''; num++) ; //去前导0
if(*num == ) --num;
len = strlen(num);
for(int i = ; i < len; ++i) s[i] = num[len-i-] - '';
return *this;
} bign operator + (const bign &b) const {
bign c;
c.len = ;
for(int i = , g = ; g || i < max(len, b.len); ++i) {
int x = g;
if(i < len) x += s[i];
if(i < b.len) x += b.s[i];
c.s[c.len++] = x % ;
g = x / ;
}
return c;
} bign operator += (const bign &b) {
*this = *this + b;
return *this;
} void clean() {
while(len > && !s[len-]) len--;
} bign operator * (const bign &b) {
bign c;
c.len = len + b.len;
for(int i = ; i < len; ++i) {
for(int j = ; j < b.len; ++j) {
c.s[i+j] += s[i] * b.s[j];
}
}
for(int i = ; i < c.len; ++i) {
c.s[i+] += c.s[i]/;
c.s[i] %= ;
}
c.clean();
return c;
}
bign operator *= (const bign &b) {
*this = *this * b;
return *this;
} bign operator - (const bign &b) {
bign c;
c.len = ;
for(int i = , g = ; i < len; ++i) {
int x = s[i] - g;
if(i < b.len) x -= b.s[i];
if(x >= ) g = ;
else {
g = ;
x += ;
}
c.s[c.len++] = x;
}
c.clean();
return c;
}
bign operator -= (const bign &b) {
*this = *this - b;
return *this;
} bign operator / (const bign &b) {
bign c, f = ;
for(int i = len - ; i >= ; i--) {
f *= ;
f.s[] = s[i];
while(f >= b) {
f -= b;
c.s[i]++;
}
}
c.len = len;
c.clean();
return c;
}
bign operator /= (const bign &b) {
*this = *this / b;
return *this;
} bign operator % (const bign &b) {
bign r = *this / b;
r = *this - r*b;
return r;
}
bign operator %= (const bign &b) {
*this = *this % b;
return *this;
} bool operator < (const bign &b) {
if(len != b.len) return len < b.len;
for(int i = len-; i >= ; i--) {
if(s[i] != b.s[i]) return s[i] < b.s[i];
}
return false;
} bool operator > (const bign &b) {
if(len != b.len) return len > b.len;
for(int i = len-; i >= ; i--) {
if(s[i] != b.s[i]) return s[i] > b.s[i];
}
return false;
} bool operator == (const bign &b) {
return !(*this > b) && !(*this < b);
} bool operator != (const bign &b) {
return !(*this == b);
} bool operator <= (const bign &b) {
return *this < b || *this == b;
} bool operator >= (const bign &b) {
return *this > b || *this == b;
} string str() const {
string res = "";
for(int i = ; i < len; ++i) res = char(s[i]+'') + res;
return res;
}
}; istream& operator >> (istream &in, bign &x) {
string s;
in >> s;
x = s.c_str();
return in;
} ostream& operator << (ostream &out, const bign &x) {
out << x.str();
return out;
} bign f[]; void solve(int n) {
f[] = f[] = f[] = f[] = ;
if(n < ) cout<<f[n]<<endl;
else {
int x = ;
for(int i = ; i <= n; ++i) {
f[] = f[] + f[] + f[] + f[];
f[x] = f[];
if(++x == ) x = ;
}
cout<<f[]<<endl;
}
} int main() {
int n;
while(scanf("%d", &n)!=EOF) {
solve(n);
}
return ;
}
HDU 1250 Hat's Fibonacci(高精度)的更多相关文章
- hdu 1250 Hat's Fibonacci(高精度数)
// 继续大数,哎.. Problem Description A Fibonacci sequence is calculated by adding the previous two membe ...
- hdu 1250 Hat's Fibonacci
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...
- HDU 1250 Hat's Fibonacci(大数相加)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 1250 Hat's Fibonacci (递推、大数加法、string)
Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)
Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...
- hdu 1250 Hat's Fibonacci(java,简单,大数)
题目 java做大数的题,真的是神器,来一道,秒一道~~~ import java.io.*; import java.util.*; import java.math.*; public class ...
- hdu 1250 Hat's Fibonacci
pid=1250">点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding ...
- HDU 4099 Revenge of Fibonacci(高精度+字典树)
题意:对给定前缀(长度不超过40),找到一个最小的n,使得Fibonacci(n)前缀与给定前缀相同,如果在[0,99999]内找不到解,输出-1. 思路:用高精度加法计算斐波那契数列,因为给定前缀长 ...
- Hat's Fibonacci(大数加法+直接暴力)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...
随机推荐
- 数据库函数(Left、Right)
MySQL 字符串截取函数:left(), right(), substring(), substring_index().还有 mid(), substr().其中,mid(), substr() ...
- Python记录键盘鼠标敲击次数
Idea 作为一个每天有一半时间都在电脑旁的人,无时无刻不在敲击着键盘,点击着鼠标.有一天,我突然很想知道在一天的时间内,在我轻盈的指法下面,键盘被我狂敲了多少下,鼠标又被我点击了多少次.甚至更具体一 ...
- docker build
nginx Docfile ----------------------- FROM centos MAINTAINER daniel RUN yum install -y wget RUN ...
- JDBC中执行sql语句的 增 , 删 , 改 , 查 的方法
executeQuery() : 执行 SELECT 语句,它几乎是使用最多的 SQL 语句 executeUpdate() : 执行 INSERT.UPDATE 或 DELETE 语句以及 S ...
- 关于如何去Apple.cn下载Xcode以及模拟器包
前言:对于一个懒惰的iOS开发,Xcode的更新我是迟迟没有去下载.有人或许会说:你并不是一个合格的iOS开发者! T3T 我承认自己缺少拓新精神,Apple的尿性是:坑死第一批体验者不偿命~表示本人 ...
- Canvas状态的保存与恢复
Canvas的API提供了save()和restore()的方法,用于保存及恢复当前canvas绘图环境的所有属性. save()与restore()方法可以嵌套调用 save()方法将当前绘图环境压 ...
- Java : logback简单配置
需要把logback.xml文件放在类路径下,如果是spring boot项目可以用 logging.config=classpath:log/xxxxxx.xml来指定配置文件 logback la ...
- CI框架视图继承
CI(CodeIgniter)框架 视图继承 这个代码不是我撸的 ... 当时在哪儿找的忘了 ... 如果有侵权什么的 ... 联系我删了 ... 需要去core里面创建一个MY_loader.php ...
- Python-入门必备
·Python入门必备 @ 交互式编程 交互式编程不需要创建脚本文件,而是直接通过Python解释器的交互模式进来编写代码.下面我们来打开python自带的交互式编程客户端,打印一个hello,wor ...
- vowels_单元音
vowels(美式): 单元音: [i]:需要用劲喊出类似于“yi”的四声,费力咧开嘴,单词eat.need.thief.meet. [?]:卷舌音,单词bird.her.worry.certain. ...