#ifndef MY_BIGN_H
#define MY_BIGN_H 1
#pragma GCC system_header
#include<cstring>
#include<algorithm>
#include<iostream>
using std::max;
using std::istream;
using std::ostream;
using std::string;

namespace zyf{
struct bign{
static const int maxlen=5000,limit=10000,width=4;
int len,bit[maxlen];
int& operator[](int p){ return bit[p]; }
void ClearBit(){ memset(bit,0,sizeof(bit)); }
void Delete0(){ for(;!bit[len-1] && len>1;--len); }

bign(int p=0){ *this=p; }
bign& operator=(int p){
ClearBit();
len=p?0:1; for(;p;p/=limit) bit[len++]=p%limit;
return *this;
}
bign(const char *p){ *this=p; }
bign& operator=(const char *p){
ClearBit();
len=0;
for(int i=strlen(p)-1;i>=0;i-=4){
int now=0;
for(int j=max(0,i-width+1);j<=i;++j) now=now*10+(p[j]-'0');
bit[len++]=now;
}
return *this;
}

bign& operator+=(bign b){
len=max(len,b.len)+1;
for(int i=0;i<len;++i) bit[i]+=b[i],bit[i+1]+=bit[i]/limit,bit[i]%=limit;
Delete0(); return *this;
}
bign& operator-=(bign b){
for(int i=0;i<len;++i){ bit[i]-=b[i]; if(bit[i]<0) bit[i]+=limit,--bit[i+1]; }
Delete0(); return *this;
}
bign& operator*=(bign b){
bign a=*this; ClearBit(); len=a.len+b.len;
for(int i=0;i<a.len;++i)
for(int j=0;j<b.len;++j)
bit[i+j]+=a[i]*b[j],bit[i+j+1]+=bit[i+j]/limit,bit[i+j]%=limit;
Delete0(); return *this;
}
bign& operator/=(int b){
for(int i=len-1;i>0;--i) bit[i-1]+=limit*(bit[i]%b),bit[i]/=b; bit[0]/=b;
Delete0(); return *this;
}

bool operator<(bign b) const{
if(len>b.len) return false;
if(len<b.len) return true;
for(int i=len-1;i>=0;--i)
if(bit[i]!=b[i]) return bit[i]<b[i];
return bit[0]<b[0];
}
bool operator==(bign b) const{ return !(*this<b) && !(b<*this); }
bool operator!=(bign b) const{ return !(*this==b); }
bool operator>(bign b) const{ return !(*this<b) && !(*this==b); }
bool operator<=(bign b) const{ return *this<b || *this==b; }
bool operator>=(bign b) const{ return *this>b || *this==b; }

bool odd(){ return bit[0]%2==1; }
bool even(){ return bit[0]%2==0; }
};
bign operator+(bign a,bign b){ return a+=b; }
bign operator-(bign a,bign b){ return a-=b; }
bign operator*(bign a,bign b){ return a*=b; }
bign operator/(bign a,int b){ return a/=b; }
istream& operator>>(istream &is,bign &p){
string s; is>>s; p=s.c_str();
return is;
}
ostream& operator<<(ostream &os,bign p){
os.fill('0'); os<<p.bit[p.len-1];
for(int i=p.len-2;i>=0;--i){ os.width(bign::width); os<<p.bit[i]; }
return os;
}

bign sqrt(bign x){
bign head=1,tail=x;
while(head<=tail){
bign mid=(head+tail)/2;
if(x<mid*mid) tail=mid-1; else head=mid+1;
}
return tail;
}
}
using zyf::bign;
#endif

dalao高精的更多相关文章

  1. Linux 高精確的時序(sleep, usleep,nanosleep) from:http://blog.sina.com.cn/s/blog_533ab41c0100htae.html

    Linux 高精確的時序(sleep, usleep,nanosleep) (2010-04-14 17:18:26) 转载▼ 标签: 杂谈 分类: linux 首先, 我会说不保证你在使用者模式 ( ...

  2. c++ 普通高精除高精

    //codevs3118 高精度练习之除法 //打出了高精除高精,内心有点小激动. //还记得已开始学的时候非常难打 #include<cstdio>#include<cstring ...

  3. c++普通高精加

    //作为一名蒟蒻,还请诸位不要吐槽. //第一次打c++高精加,内心有点小激动. //为codevs3116 高精度练习之加法 //程序太简单,就不打注释了. #include<cstdio&g ...

  4. BZOJ_1002_[FJOI2007]_轮状病毒_(递推+高精)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1002 )*&*(^&*^&*^**()*) 1002: [FJOI20 ...

  5. bzoj 3287: Mato的刷屏计划 高精水题 && bzoj AC150

    3287: Mato的刷屏计划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 124  Solved: 43[Submit][Status] Desc ...

  6. codevs 3119 高精度练习之大整数开根 (各种高精+压位)

    /* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...

  7. vijos P1375 大整数(高精不熟的一定要做!)

    /* 我尼玛这题不想说啥了 亏了高精写的熟..... 加减乘除max都写了 高精二分 */ #include<iostream> #include<cstdio> #inclu ...

  8. noip 2012 国王游戏(贪心+高精)

    /* 我是不会说我考试的时候想到了正解却把金币取大看成金币求和的.... 觉得只按左右手乘积排序不太对 有反例 也可能我反例放到这个题里是错的吧 按自己的理解排的序 就是各种讨论... 假设 第i个人 ...

  9. noip推荐系列:遥控车[字符串+高精+二分答案]

    [问题描述] 平平带着韵韵来到了游乐园,看到了n辆漂亮的遥控车,每辆车上都有一个唯一的名字name[i].韵韵早就迫不及待地想玩名字是s的遥控车.可是韵韵毕竟还小,她想象的名字可能是一辆车名字的前缀( ...

随机推荐

  1. HTTP响应报文应答状态码及含义

    本应答报文状态码是老猿结合多方资料收集综合后并加以老猿自己的理解进行说明的应答报文状态码,应该是最新最全解释最详尽的,供大家参考:

  2. PyQt(Python+Qt)学习随笔:QTableView的showGrid属性

    老猿Python博文目录 老猿Python博客地址 showGrid属性用于控制视图中数据项之间是否显示网格,如果该属性为True,则绘制网格:如果该属性为False,则不绘制网格. showGrid ...

  3. 移动端web网页meta设置

    <meta charset='utf-8'><!-- 声明文档使用的字符编码 --> <meta http-equiv="X-UA-Compatible&quo ...

  4. vue结合element-ui实现二级复选框checkbox

    vue结合element-ui实现二级复选框checkbox 话不多说先上效果 交互:1.点击按钮全选,所有的checkbox全部选中:点击清空,所有的checkbox框都不选:点击确定获取选中的ch ...

  5. 【Codeforces 809E】Surprise me!(莫比乌斯反演 & 虚树)

    Description 给定一颗 \(n\) 个顶点的树,顶点 \(i\) 的权值为 \(a_i\).求: \[\frac{1}{n(n-1)}\sum_{i=1}^n\sum_{j=1}^n\var ...

  6. 题解-[国家集训队]Crash的数字表格 / JZPTAB

    题解-[国家集训队]Crash的数字表格 / JZPTAB 前置知识: 莫比乌斯反演 </> [国家集训队]Crash的数字表格 / JZPTAB 单组测试数据,给定 \(n,m\) ,求 ...

  7. 题解-[SDOI2014]数数

    [SDOI2014]数数 这题的前置知识是AC自动机和dp,前置题目是 [JSOI2007]文本生成器,前置题目我写的题解 题解-[JSOI2007]文本生成器.我的讲解假设你做过上面那道题. 这题比 ...

  8. fabric智能合约模板

    以创建用户为例,我觉得基本都是这个框架,用特殊功能直接再往上加,欢迎留言交流 func createUser(stub shim.ChaincodeStubInterface, args []stri ...

  9. activiti环境安装

    使用Eclipse安装activiti插件的时候,没有安装成功,参考这边文章才成功,链接:https://jingyan.baidu.com/article/4dc408480d4201c8d846f ...

  10. MVC部署出现403.14问题记录

    1.问题截图 2.解决办法有几种 1)在system.webServer下增加,这种是不推荐的. <modules runAllManagedModulesForAllRequests=&quo ...