该模板不是本人的,但是该是加了个头文件哒。不然在某个oj上编译错误。

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
struct bign{
int d[maxn], len;
void clean() { while (len > && !d[len - ]) len--; }
bign() { memset(d, , sizeof(d)); len = ; }
bign(int num) { *this = num; }
bign(char* num) { *this = num; }
bign operator = (const char* num){
memset(d, , sizeof(d)); len = strlen(num);
for (int i = ; i < len; i++) d[i] = num[len - - i] - '';
clean();
return *this;
}
bign operator = (int num){
char s[]; sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator + (const bign& b){
bign c = *this; int i;
for (i = ; i < b.len; i++){
c.d[i] += b.d[i];
if (c.d[i] > ) c.d[i] %= , c.d[i + ]++;
}
while (c.d[i] > ) c.d[i++] %= , c.d[i]++;
c.len = max(len, b.len);
if (c.d[i] && c.len <= i) c.len = i + ;
return c;
}
bign operator - (const bign& b){
bign c = *this; int i;
for (i = ; i < b.len; i++){
c.d[i] -= b.d[i];
if (c.d[i] < ) c.d[i] += , c.d[i + ]--;
}
while (c.d[i] < ) c.d[i++] += , c.d[i]--;
c.clean();
return c;
}
bign operator * (const bign& b)const{
int i, j; bign c; c.len = len + b.len;
for (j = ; j < b.len; j++) for (i = ; i < len; i++)
c.d[i + j] += d[i] * b.d[j];
for (i = ; i < c.len - ; i++)
c.d[i + ] += c.d[i] / , c.d[i] %= ;
c.clean();
return c;
}
bign operator / (const bign& b){
int i, j;
bign c = *this, a = ;
for (i = len - ; i >= ; i--)
{
a = a * + d[i];
for (j = ; j < ; j++) if (a < b*(j + )) break;
c.d[i] = j;
a = a - b*j;
}
c.clean();
return c;
}
bign operator % (const bign& b){
int i, j;
bign a = ;
for (i = len - ; i >= ; i--)
{
a = a * + d[i];
for (j = ; j < ; j++) if (a < b*(j + )) break;
a = a - b*j;
}
return a;
}
bign operator += (const bign& b){
*this = *this + b;
return *this;
}
bool operator <(const bign& b) const{
if (len != b.len) return len < b.len;
for (int i = len - ; i >= ; i--)
if (d[i] != b.d[i]) return d[i] < b.d[i];
return false;
}
bool operator >(const bign& b) const{ return b < *this; }
bool operator<=(const bign& b) const{ return !(b < *this); }
bool operator>=(const bign& b) const{ return !(*this < b); }
bool operator!=(const bign& b) const{ return b < *this || *this < b; }
bool operator==(const bign& b) const{ return !(b < *this) && !(b > *this); }
string str() const{
char s[maxn] = {};
for (int i = ; i < len; i++) s[len - - i] = d[i] + '';
return s;
}
}; istream& operator >> (istream& in, bign& x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream& out, const bign& x)
{
out << x.str();
return out;
}
int main()
{ }

高精度(x ,/, +, -, %)良心模板的更多相关文章

  1. C++高精度整数加减乘除模板

    其中高精度乘法通过了POJ2389,其他没有测过,不过应该是没有问题的. 其中高精度除法返回一对string,分别表示商和余数. 代码: #include <bits/stdc++.h> ...

  2. PAT A1024题解——高精度大数相加模板

    PAT:A1024 Palindromic Number A number that will be the same when it is written forwards or backwards ...

  3. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  4. POJ 2325 Persistent Numbers#贪心+高精度除法

    (- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...

  5. JDOJ 1790: 高精度A-B

    JDOJ 1790: 高精度A-B JDOJ传送门 洛谷 P2142 高精度减法 洛谷传送门 题目描述 高精度减法 输入格式 两个整数a,b(第二个可能比第一个大) 输出格式 结果(是负数要输出负号) ...

  6. Noip2016

    <这篇是以前的,不开新的了,借版面来换了个标题> 高二了 开学一周,每天被文化课作业碾压... 但是仍然阻挡不了想刷题的心情... 对付noip2016的几块:(有点少,以后补) 高精度( ...

  7. bc#29 做题笔记

    昨天的bc被坑惨了= = 本来能涨rating的大好机会又浪费了...大号已弃号 A:第一反应是高精度,结果模板找不到了= =,然后现学现卖拍了个java的BigInteger+快速幂,调了好半天不说 ...

  8. 【BZOJ1500】【NOI2005】维修数列(Splay)

    [BZOJ1500][NOI2005]维修数列(Splay) 题面 不想再看见这种毒瘤题,自己去BZOJ看 题解 Splay良心模板题 真的很简单 我一言不发 #include<iostream ...

  9. 【SHOI2012】魔法树(树链剖分,线段树)

    [SHOI2012]魔法树 题面 BZOJ上找不到这道题目 只有洛谷上有.. 所以粘贴洛谷的题面 题解 树链剖分之后直接维护线段树就可以了 树链剖分良心模板题 #include<iostream ...

随机推荐

  1. ubantu 安装杀毒软件 clamav

    前言: 搜索了一番安装杀毒软件的教程, 但是多有残缺不全的, 所以整理一下,以作记录 1. 添加用户 groupadd clamav useradd -g clamav -s /bin/false - ...

  2. echarts环形图,自定义说明文字

    一.代码 app.title = '已安装通讯盒电站统计'; option = { backgroundColor: '#0f0f31',//#0f0f31 title: { show:true, x ...

  3. extract-text-webpack-plugin 作用、安装、使用

    作用:该插件的主要是为了抽离css样式,防止将样式打包在js中引起页面样式加载错乱的现象 安装:插件安装命令如下: npm install extract-text-webpack-plugin -- ...

  4. JMeter JMeter自身运行性能优化

    JMeter自身运行性能优化   by:授客 QQ:1033553122 测试环境 apache-jmeter-2.13   1.   问题描述 单台机器的下JMeter启动较大线程数时可能会出现运行 ...

  5. JMeter Sampler之BeanShellSampler的使用

    Sampler之BeanShellSampler的使用 by:授客 QQ:1033553122 欢迎加入软件性能测试交流群:7156436 1.  Bean Shell简介 ·         Bea ...

  6. [SQL SERVER] The CHECK_POLICY and CHECK_EXPIRATION options cannot be turned OFF when MUST_CHANGE is ON. (Microsoft SQL Server, Error: 15128)

    The CHECK_POLICY and CHECK_EXPIRATION options cannot be turned OFF when MUST_CHANGE is ON. (Microsof ...

  7. ubuntu通过apt-get安装JDK8

    安装python-software-properties apt-get install python-software-properties apt-get install software-pro ...

  8. LVS (Linux Virtual Server) - 负载均衡集群 - keepalived

    今天稍微了解了LVS 的原理和使用,在网络上找到不少好文章,稍微加以处理并在这里备份: 原理介绍:Linux Virtual Server 关于:http://www.linuxvirtualserv ...

  9. shell中>/dev/null 2>&1

    本文转自http://www.kissyu.org/ 背景 我们经常能在shell脚本中发现>/dev/null 2>&1这样的语句.以前的我并没有去深入地理解这段命令的作用,照搬 ...

  10. SVN与Git比较的优缺点差异

    目录: SVN与Git比较(一)集中式vs分布式 SVN与Git比较(二)版本库与工作区 SVN与Git比较(三)全局版本号和全球版本号 SVN与Git比较(四)部分检出 SVN与Git比较(五)更新 ...