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 ...
随机推荐
- centos、mac的grafana安装和简单使用
1.安装: 参考官方文档安装说明:https://grafana.com/grafana/download Redhat & Centos(64 Bit): wget https://s3-u ...
- Codeforces554E:Love Triangles
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves B ...
- Web容器自己主动对HTTP请求中參数进行URLDecode处理
这篇文章转载自 : Web容器自己主动对HTTP请求中參数进行URLDecode处理 如题.在Java中或许非常多人都没有注意到当我们发送一个http请求时,假设附带的參数被URLEncode之后,到 ...
- 【网络】TCP的拥塞控制
一.拥塞控制的一般原理 拥塞:对网络中某一资源的需求超过了该资源所能提供的可用部分 拥塞控制是防止过多的数据注入到网络,这样可以使网络中的路由器或链路不致过载,拥塞控制是一个全局性的过程. 流量控制往 ...
- POJ2752 Seek the Name, Seek the Fame 【KMP】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11602 Ac ...
- LeetCode题解汇总
陆续更新至github... https://github.com/OliveLv/LeetCode/
- Pierce振荡器设计
一.Pierce振荡器电路 Inv:内部反相器,作用等同于放大器: Q:石英晶体或陶瓷晶振: RF:内部反馈电阻(使反相器工作在线性区): RExt:外部限流电阻(防止石英晶体被过分驱动): CL1. ...
- 刚刚做了个文件上传功能,拿来分享一下!(MVC架构及传统架构通用)
文件上传无论在软件还是在网站上都十分常见,我今天再把它拿出来,讲一下,主要讲一下它的设计思想和实现技术,为了它的通用性,我把它做在了WEB.Service项目里,即它是针对服务器的,它的结构是关联UI ...
- 2016/2/24 1,css有几种引入方式 2,div除了可以声明id来控制,还可以声明什么控制? 3,如何让2个div,并排显示。4,清除浮动 clear:left / right / both
1,css有几种引入方式 使用HTML标签的STYLE属性 将STYLE属性直接加在单个的HTML元素标签上,控制HTML标签的表现样式.这种引入CSS的方式是分散灵活方便,但缺乏整体性和规划性,不利 ...
- ECharts 使用
最近项目中要做图形报表,要求使用echarts实现,图形报表有很多中实现之前也接触过,但echarts还是头一次听说,正好可以趁这个机会好好学习一下它. 之前不知道就不知道啦,现在知道了就了不得了,一 ...