How many Fibs? POJ - 2413

高精模板

 #include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long B_INT;
const char p_c[]="%08lld";
const char i_c[]="%lld";
int l1,l2;
struct Bigint
{
/*
基本类型(char,int,float,double等)的静态成员可以在类里面声明并初始化,
非基本类(char[],string ,自定义等)必须在类里面声明,类外初始化。
*/
static const B_INT p=;//压p位,int压4位加乘法可能导致溢出
static const B_INT base=;//压p位,最大数为10^p-1
static const int maxl=;
B_INT a[maxl];//a[0]->len,a[i]->从后往前数第i个p位
Bigint()
{
memset(a,,sizeof(a));
}
// Bigint(char *str)
// {
// memset(a,0,sizeof(a));
// B_INT k=0,p=1;
// char *str1=str+strlen(str)-1;
// while(str1>=str)
// {
// k=k+p*(*str1-48);
// if(p==base)
// {
// a[++a[0]]=k%base;
// k/=base;
// p=1;
// }
// str1--;
// p*=10;
// }
// a[++a[0]]=k;
// }
Bigint(const Bigint& b)
{
memcpy(a,b.a,sizeof(a));
}
Bigint& operator=(const Bigint& b)
{
memcpy(a,b.a,sizeof(a));
return *this;
}
Bigint& operator=(char *str)
{
memset(a,,sizeof(a));
B_INT k=,p=;
char *str1=str+strlen(str)-;
while(str1>=str)
{
k=k+p*(*str1-);
if(p==base)
{
a[++a[]]=k%base;
k/=base;
p=;
}
str1--;
p*=;
}
a[++a[]]=k;
return *this;
}
Bigint operator+(const Bigint &b) const
{
Bigint c;
B_INT i;
c.a[]=std::max(a[],b.a[]);
for(i=;i<=c.a[];i++)
{
c.a[i]+=a[i]+b.a[i];
c.a[i+]=c.a[i]/base;
c.a[i]%=base;
}
if(c.a[c.a[]+]>)
c.a[]++;
return c;
}
Bigint operator*(const Bigint &b) const
{
Bigint c;
B_INT i,j;
for(i=;i<=a[];i++)
for(j=;j<=b.a[];j++)
c.a[i+j-]+=a[i]*b.a[j];
c.a[]=a[]+b.a[]-;
for(i=;i<=c.a[];i++)
{
c.a[i+]+=c.a[i]/base;
c.a[i]%=base;
}
if(c.a[c.a[]+]>)
c.a[]++;
return c;
}
Bigint operator-(const Bigint &b) const//要求保证减数小于被减数
{
Bigint c;
B_INT i;
c.a[]=std::max(a[],b.a[]);
for(i=;i<=c.a[];i++)
c.a[i]=a[i]-b.a[i];
for(i=;i<=c.a[];i++)
if(c.a[i]<)
{
c.a[i]+=base;
c.a[i+]--;
}
while(c.a[c.a[]]==&&c.a[]>)
c.a[]--;
return c;
}
Bigint& operator+=(const Bigint &b)
{
*this=*this+b;
return *this;
}
Bigint& operator-=(const Bigint &b)
{
*this=*this-b;
return *this;
}
Bigint& operator*=(const Bigint &b)
{
*this=(*this)*b;
return *this;
}
bool operator<(const Bigint &b) const
{
if(a[]!=b.a[])
return a[]<b.a[];
for(B_INT i=a[];i>;i--)
if(a[i]!=b.a[i])
return a[i]<b.a[i];
return false;//相等
}
/*
非静态成员函数后面加const(加到非成员函数或静态成员后面会产生编译错误),
表示成员函数隐含传入的this指针为 const指针,
决定了在该成员函数中,
任意修改它所在的类的成员的操作都是不允许的
(因为隐含了对this指针的const引用);
唯一的例外是对于 mutable修饰的成员。
加了const的成员函数可以被非const对象和const对象调用,
但不加const的成员函数只能被非const对象调用。
下方b是const,const函数不能修改其数据成员
*/
bool operator>(const Bigint &b) const
{
return b<*this;
/*
if(a[0]!=b.a[0])
return a[0]>b.a[0];
for(int i=a[0];i>0;i--)
if(a[i]!=b.a[i])
return a[i]>b.a[i];
return false;//相等
*/
}
bool operator<=(const Bigint &b) const
{
return !(b<*this);
/*
if(a[0]!=b.a[0])
return a[0]>b.a[0];
for(int i=a[0];i>0;i--)
if(a[i]!=b.a[i])
return a[i]>b.a[i];
return true;//相等
*/
}
bool operator>=(const Bigint &b) const
{
return !(*this<b);
/*
if(a[0]!=b.a[0])
return a[0]>b.a[0];
for(int i=a[0];i>0;i--)
if(a[i]!=b.a[i])
return a[i]>b.a[i];
return true;//相等
*/
}
bool operator==(const Bigint &b) const
{
if(a[]!=b.a[])
return false;
for(B_INT i=a[];i>;i--)
if(a[i]!=b.a[i])
return false;
return true;
}
bool operator!=(const Bigint &b) const
{
return !(*this==b);
}
void print()
{
printf(i_c,a[a[]]);
for(B_INT i=a[]-;i>;i--)
printf(p_c,a[i]);
}
}x[],y,z;
char str1[],str2[];
int main()
{
int i;
x[]="";
x[]="";
for(i=;i<=;i++)
x[i]=x[i-]+x[i-];
scanf("%s%s",str1,str2);
while(strcmp(str1,"")!=||strcmp(str2,"")!=)
{
y=str1;
z=str2;
for(l1=;l1<=;l1++)
if(x[l1]>=y)
break;
for(l2=;l2<=;l2++)
if(x[l2]>z)
break;
printf("%d\n",l2-l1);
memset(str1,,sizeof(str1));
memset(str2,,sizeof(str2));
scanf("%s%s",str1,str2);
}
return ;
}

How many Fibs? POJ - 2413的更多相关文章

  1. How many Fibs?(poj 2413)大数斐波那契

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/C Description Recall the defi ...

  2. POJ 2413 How many Fibs?#二分+大数加法

    http://poj.org/problem?id=2413 #include<iostream> #include<cstdio> #include<cstring&g ...

  3. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  4. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  5. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  6. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  7. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  8. POJ题目分类(转)

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. 如何在Win7 x64上的配置32位的PostgreSQL ODBC数据源

    在Win7 x64下安装最新版的PostgreSQL 9.x 后,从其官网下载最新的 ODBC驱动,分为普通的32位和64位版本,正常安装后,从已安装软件列表里可以看到两个版本的驱动都已经正确显示出来 ...

  2. Python遍历路径下文件并转换成UTF-8编码

    http://www.cnblogs.com/wuyuegb2312/archive/2013/01/11/2856772.html 开始学Python,这篇文章来自于应用需求. os.walk很方便 ...

  3. js实现动态删除表格的行或者列-------Day57

    昨天记录了动态加入表格的一行,当然这个一行是指一行数据,也就是说一行多少列也是加上的,而且第几列的内容都能够加入上,先来回想下它的实现的关键点: 1.var row=table.insertRow() ...

  4. vue :src 文件路径错误

    首先先说明下vue-cli的assets和static的两个文件的区别,因为这对你理解后面的解决办法会有所帮助 assets:在项目编译的过程中会被webpack处理解析为模块依赖,只支持相对路径的形 ...

  5. Python的字符串和列表和字典的方法/函数

    字符串 S.find()#可指定范围查找字串,返回索引值,否则返回-1 S.index()#同find,只是找不到的之后返回异常 S.count()#返回找到字串的个数 S.lower()#转小写 S ...

  6. Kemans算法及其Python 实现

    算法优缺点: 优点:容易实现缺点:可能收敛到局部最小值,在大规模数据集上收敛较慢使用数据类型:数值型数据 算法思想 k-means算法实际上就是通过计算不同样本间的距离来判断他们的相近关系的,相近的就 ...

  7. oracle的日期蛋

    一切都是扯鸡巴蛋. 在网上查oracle的日期函数用法,得到一大堆语法,林林总总,都是扯鸡巴蛋,没能解决我的问题. 其实,我想写这么一条语句:查找某个日期(不含时分秒)产生或有关的记录.咋写? SQL ...

  8. mysql + Fluently NHibernate + WebAPI + Autofac

    MySQL.Fluently NHibernate.WebAPI.Autofac,对我来说每一个都是麻烦疙瘩,现在它们为了一个共同的项目而凑合到一起了.一路磕磕碰碰,现在貌似有了一点眉目. 作为一个步 ...

  9. VS创建Web项目提示配置IISExpress失败

    开发服务器VS2013,新建Web项目提示: 打开Web项目提示: 解决方法:控制面板,找到IISExpress,右键 选择修复,解决问题..

  10. 【转】wait和waitpid详解

    发现进程有关的编程题里面的包含知识量实在是太庞大,这是关于wait和waitpid区别的,以前只是粗略知道它们的区别,这是网上看到的比较全的对比 转自http://blog.chinaunix.net ...