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的更多相关文章
- How many Fibs?(poj 2413)大数斐波那契
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/C Description Recall the defi ...
- POJ 2413 How many Fibs?#二分+大数加法
http://poj.org/problem?id=2413 #include<iostream> #include<cstdio> #include<cstring&g ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目分类(转)
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
随机推荐
- java nio实现非阻塞Socket通信实例
服务器 package com.java.xiong.Net17; import java.io.IOException; import java.net.InetSocketAddress; imp ...
- IPTABLES基本例子
iptables –F #删除已经存在的规则 iptables -P INPUT DROP #配置默认的拒绝规则.基本规则是:先拒绝所有的服务,然后根据需要再添加新的规则. iptables -A I ...
- Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 A new e-mail service "Berlandesk&q ...
- cocos2d-x进化为2.5D的一些想法
首先我得说Unity3D已经做的非常好了,搞这些东西意义真心不大.详细Unity3D有什么优势我之前也写过两篇文章来阐述自己的想法. 假设我的下一份工作是U3D的话,预计我就不会 ...
- 淘宝API学习之道:淘宝TOP之API接口接入教程
作为一个中小型站点开发人员,淘宝API的开放大大缩短了站点的开发周期和运作效率.面对海量的数据.开发人员仅仅要细致阅读开发文档,熟悉对应的接口,就能够把数据导入自己的站点,这样就不必望洋兴叹了. 眼下 ...
- httpclient发送get请求
/** * 获取httpclient的请求url地址 */ public static String getUrl(){ String url = "http://"+map.ge ...
- 【CODEFORCES】 C. Dreamoon and Strings
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 李洪强iOS开发之函数式 编程初窥
函数式 编程初窥 最近在学习Erlang和Python.Erlang是完全的函数式编程语言,Python语言是面向对象的语言,但是它的语法引入了大量的函数式编程思想.越研究越觉得函数式的编程思路可 ...
- hdu 4970 Killing Monsters(数组的巧妙运用) 2014多校训练第9场
pid=4970">Killing Monsters ...
- 不同linux版本下内核/系统/软件的安装及查询
(一)先介绍下使用apt-get 和使用yum 包管理工具的不同用法: 1.先看yum(redhat) yum的配置文件是/etc/yum.conf 更新:yum update 安装:yum inst ...