首页 > 其他分享 >高精度模板

高精度模板

时间:2024-07-20 19:18:59浏览次数:5  
标签:const val 高精度 int len return BigNum 模板

高精度模板

struct BigNum {
    int val[N], len = 1;
    void init() { val[1] = len = 1; }
    BigNum operator + (const BigNum &x) const {
        static BigNum t = *this;
        t.len = max(t.len, x.len);
        for (int i = 1; i <= t.len; i++) t.val[i] += x.val[i];
        for (int i = 1; i <= len; i++) t.val[i + 1] += t.val[i] / 10, t.val[i] %= 10;
        while (t.val[len] > 9) t.val[len + 1] += t.val[len] / 10, t.val[len] %= 10, t.len++;
        return t;
    }
    BigNum operator - (const BigNum &x) const {
        static BigNum t = *this;
        t.len = max(t.len, x.len);
        for (int i = 1; i <= max(t.len, x.len); i++) t.val[i] -= x.val[i];
        for (int i = 1; i <= len; i++) 
            if (t.val[i] < 0) 
                t.val[i] += (9 - t.val[i]) / 10 * 10, t.val[i + 1] -= (9 - t.val[i]) / 10 * 10;
        while (t.len > 1 && t.val[len] == 0) t.len--;
        return t;
    }
    BigNum operator * (const BigNum &x) const {
        static BigNum t = *this;
        for (int i = 1; i <= t.len; i++) 
            for (int j = 1; j <= x.len; j++) 
                t.val[i + j - 1] += val[i] * x.val[j];
        for (int i = 1; i <= t.len + x.len; i++) t.val[i + 1] += t.val[i] / 10, t.val[i] %= 10;
        t.len += x.len;
        while (t.len > 1 && t.val[len] == 0) t.len--;
        return t;
    }
    BigNum operator / (int x) const{
        static BigNum t;
        int s = 0;
        for (int i = t.len - 1; i >= 0; i--) {
            s = s * 10 + t.val[i];
            t.val[i] = s / x;
            s %= x;
        }
        while (t.len > 0 && val[t.len - 1] == 0) t.len--;
        return t;
    }
    int cmp(const BigNum &x) const {
        if (len != x.len) return len < x.len;
        for (int i = len; i >= 1; i--) if (val[i] != x.val[i]) return val[i] < x.val[i];
        return 2;
    }
    bool operator < (const BigNum &x) const {
        return !cmp(x);
    }
    bool operator = (const BigNum &x) const {
        return cmp(x) == 2;
    }
    bool operator > (const BigNum &x) const {
        return cmp(x);
    }
    void print() const{
        for (int i = len; i >= 1; i--) printf("%d", val[i]);
        puts("");
    }
};

标签:const,val,高精度,int,len,return,BigNum,模板
From: https://www.cnblogs.com/louyuxuan/p/18313606

相关文章

  • 易优CMS模板标签load文件加载导入外部的css样式文件
    【基础用法】标签:load描述:资源文件加载,比如:css/js用法:{eyou:loadhref='/static/js/common.js'ver='on'/}属性:file=''资源文件路径href=''远程资源文件URLver=''开启版本号自动刷新浏览器缓存涉及表字段:无【更多示例】-------------------------------示例1------......
  • 易优CMS模板标签global全局变量输出网站关键词
    【基础用法】标签:global描述:获取系统全局配置变量内容用法:{eyou:globalname='web_title'/}或者{$eyou.global.web_title}文件:系统模板引擎属性:name=''变量名涉及表字段:请查阅网站后台的【设置】-【基本信息】web_status关闭网站web_name网站名称web_logo网站LOGO......
  • 帝国CMS网站增加手机WAP模板步骤说明
    一、增加WAP模板步骤说明:1、先制作好WAP模板文件(/e/wap/template/);2、登录后台管理WAP模板里增加刚才做好的WAP模板目录;3、WAP设置里选择新WAP模板测试;4、完成。二、WAP设置:1、登录后台,单击“栏目”菜单,选择“WAP设置”子菜单,进入WAP设置界面:2、进入WAP设置界面:开启WAP ......
  • 微信小程序--7(WXSS模板样式)
    目录一、概念二、扩展特性     (一)rpx尺寸单位(二)@import样式导入三、全局样式与局部样式(一)全局样式(二)局部样式一、概念        WXSS是一套样式语言,用来美化WXML的组件样式,类似网页开发中的CSS。二、扩展特性             与CSS相......
  • 算法基础课第一章(中)高精度+前缀和+差分
    一、高精度(一)使用高精度的原因在计算机中处理非常大或非常小的数值时,确保计算结果的精确性和准确性。在特定情况下,可以自己实现高精度计算的数据结构和算法,例如使用字符串或数组来表示大数,并实现基本的加、减、乘、除操作。(二)高精度加法1、方法(1)描述:从最低位开始加法计算......
  • P3805 【模板】manacher
    原题链接题解细节所有字符的回文半径初始化为1rmax=1ans=1code#include<bits/stdc++.h>#definelllonglongusingnamespacestd;voidsolve(){strings;cin>>s;strings1;for(inti=0;s[i];i++){s1+='#';s1+=......
  • 日常记录-FreeMarker模板简单使用
    1.依赖包<dependency>   <groupId>org.freemarker</groupId>   <artifactId>freemarker</artifactId>   <version>2.3.30</version></dependency>2.工具类 importfreemarker.template.Configuration;importfreemarke......
  • P3373 【模板】线段树 2(区间乘+加操作,先乘后加原则)
    题目来源:https://www.luogu.com.cn/problem/P3373//题意:对区间[l,r]可以乘法,加法操作,查询和操作。//思路:既有乘法又有加法,肯定是要有两个标记。纯加法和纯乘法操作是很简单的,但是既有乘法又有加法涉及到先乘后加和先加后乘的顺序。//////所以现在是如何将先加后成也可以......
  • [WesternCTF2018]shrine(Jinja2模板注入)
    首先判断出是Jinja2模板注入判断方法https://www.cnblogs.com/dghh/p/18307622importflaskimportos#创建一个Flask应用实例app=flask.Flask(__name__)#从环境变量中读取'FLAG'并设置到应用配置中app.config['FLAG']=os.environ.pop('FLAG')#定义根路径('/......
  • 易优CMS模板标签uitype栏目调用在模板文件index.htm中调用uitype标签,实现指定栏目可视
    【基础用法】标签:uitype描述:栏目编辑,比uitext、uihtml、uiupload标签多了一个typeid属性,使用时结合html一起才能完成可视化布局,只针对具有可视化功能的模板。用法:<divclass="eyou-edit"e-id="文件模板里唯一的数字ID"e-page='文件模板名'e-type="type">{eyou:uitypetypeid=......