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. AE的Annotation学习摘记

    http://xg-357.blog.163.com/blog/static/36263124201151763512894/ IFeatureWorkspaceAnno pFWSAnno = (IF ...

  2. CSS浮动通俗讲解

    首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流.如下图: 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为d ...

  3. Deepin-安装node

    点击下载:Linux x64 文件解压: 方式1$xz -d file.tar.xz $tar -xvf file.tar 方式2 $tar xvJf file.tar.xz 解压后,把它移动到:/u ...

  4. 《The Swift Programming Language》的笔记-第27页

    页 1 type safelanguage 本页的主要内容是说swift语言是"类型检查"的安全型编程语言.意思是赋值语句的左值和右值的类型要一致,左值声明是string型变量那么 ...

  5. 阿里云 oss 小文件上传进度显示

    对阿里云OSS上传小文件时的进度,想过两个方法:一是.通过多线程监測Inputstream剩余的字节数来计算,可是由于Inputstream在两个线程中共用,假设上传线程将Inputstream关闭, ...

  6. CSS制作翻牌特效

    应一个朋友要求替他把原本静态页面做成翻牌的特效. 主要应用了CSS3的transform,transiton.首先写好标签,一个ul下两个li元素,通过position的absolue设置两个li元素 ...

  7. Python开发【第2节】【Python运算符】

    Python语言支持以下类型的运算符: 算术运算符 比较(关系)运算符 赋值运算符 逻辑运算符 位运算符 成员运算符 身份运算符 运算符优先级 1.算术运算符 假设变量a = 10,变量b = 21: ...

  8. Android实战简易教程-第四十枪(窃听风云之短信监听)

    近期在做监听验证码短信自己主动填入的功能,无意间想到了一个短信监听的办法. 免责声明:短信监听本身是一种违法行为,这里仅仅是技术描写叙述.请大家学习技术就可以.(哈哈) 本实例是基于bmob提供的后台 ...

  9. Hibernate 之 Why?

    本文主要是从一个宏观的角度来认识Hibernate,对为什么用Hibernate进行一些说明,通过指导并了解Hibernate的特性及其优缺点可以让我们在以后的项目中根据具体的情况进行选择. Hibe ...

  10. hdfs对namenode format 之后 应该首先检查内存消耗情况,以判断是否支持开启yarn

    http://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-common/yarn-default.xml  3.0.0 yarn.sc ...