90pts,WA#10求助
查看原帖
90pts,WA#10求助
304550
black_trees楼主2022/1/24 21:08

RT,看数据是高精除法出了问题,看很久了也没发现为啥。

我个人觉得可能是二分写错了或者 <= 的重载挂了。

但还没发现原因,求dalao看看 /kk

/*
 * @Author: black_trees 
 * @Date: 2022-01-24 15:39:38 
 * @Last Modified by: black_trees
 * @Last Modified time: 2022-01-24 21:05:23
 */
#include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int base=1ll*1e8;
constexpr int si=1ll*(1e4+10);
#undef int
constexpr int bit=8;
struct python{
    #define int long long
    int len,x[si];
    python(){ len=1,memset(x,0,sizeof(x)); } // checked.ok.
    inline void print(){
        printf("%lld",x[len]);
        for(register int i=len-1;i>=1;--i){
            printf("%0*lld",bit,x[i]);
        } return ;
    } // checked.ok.
    inline python & fix(){
        for(register int i=1;i<=len-1;++i){
            if(x[i]<0) x[i]+=base,x[i+1]-=1;
            x[i+1]+=x[i]/base,x[i]%=base;
        }
        while(x[len]>=base){
            x[len+1]+=x[len]/base;
            x[len]%=base,len++;
        }
        while(x[len]==0 && len>1) --len;
        return *this;
    } // checked.ok.
    inline python & operator = (string str){
        int l=str.size();
        len=ceil(l/float(bit));
        for(register int i=1;i<=len;++i){
            for(register int j=max(0ll,l-bit*i);j<l-bit*(i-1);++j){
                x[i]=x[i]*10+str[j]-'0';
            }
        } return *this;
    } // checked.ok.
    inline bool operator < (const python &a)const{
        if(len!=a.len) return len<a.len;
        for(register int i=len;i>=1;--i){
            if(x[i]!=a.x[i]) return x[i]<a.x[i];
        } return false;
    } // checked.ok.
    inline bool operator <= (const python &a)const{
        if(len!=a.len) return len<a.len;
        for(register int i=len;i>=1;--i){
            if(x[i]!=a.x[i]) return x[i]<a.x[i];
        } return true;
    } // checked.ok.
    inline python operator + (const int &a)const{
        python ret=*this;
        ret.x[1]+=a;
        return ret.fix();
    } // checked.ok.
    inline python operator - (const int &a)const{
        python ret=*this;
        ret.x[1]-=a;
        return ret.fix();
    } // checked.ok.
    inline python operator * (const int &a)const{
        python ret=*this;
        for(register int i=1;i<=len;++i){
            ret.x[i]*=a;
        } return ret.fix();
    } // checked.ok.
    inline python operator / (const int &a)const{
        if(a==0) puts("error:divide by zero");
        python ret; int rest=0; ret.len=len;
        for(register int i=len;i>=1;--i){
            ret.x[i]=(rest*base+x[i])/a;
            rest=(rest*base+x[i])%a;
        } return ret.fix();
    } // problems found : should write rest*base+x[i] ,but not +ret.x[i]; 
    // checked.ok.   
    inline python operator % (const int &a)const{
        python ret=*this,p=ret/a;
        ret=ret-p*a;
        return ret.fix();
    } // problems found : should write ret-p*a ,but not ret-p*ret;
    // checked.ok.
    inline python operator + (const python &a)const{
        python ret; ret.len=max(len,a.len);
        for(register int i=1;i<=ret.len;++i){
            ret.x[i]=x[i]+a.x[i];
        } return ret.fix();
    } // checked.ok.
    inline python operator - (const python &a)const{
        python ret; ret.len=max(len,a.len)+1;
        for(register int i=1;i<=ret.len;++i){
            ret.x[i]=x[i]-a.x[i];
        } return ret.fix();
    } 
    inline python operator * (const python &a)const{
        python ret; ret.len=len+a.len-1;
        for(register int i=1;i<=len;++i){
            for(register int j=1;j<=a.len;++j){
                ret.x[i+j-1]+=x[i]*a.x[j];
            }
        } return ret.fix();
    } // problems found : should write += ,but not =
    // checked.ok.
    inline python operator / (const python &a)const{
        python ret,rest;
        if(*this<a) return ret;
        int l,r,mid,res=0;
        for(register int i=len;i>=1;--i){
            rest=rest*base+x[i];
            l=0,r=base;
            while(l<r){
                mid=(l+r+1)>>1;
                if(a*mid<=rest) res=mid,l=mid;
                else r=mid-1;
            } ret.x[i]+=res,rest=rest-a*res;
        }
        return ret.fix();
    }
    inline python operator % (const python &a)const{
        python ret=*this,p=ret/a;
        ret=ret-p*a;
        return ret.fix();
    }
    #undef int
}a,b;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("Input.txt","r",stdin);
        freopen("Output.txt","w",stdout);
    #endif
    string s;
    cin>>s,a=s,cin>>s,b=s;
    (a+b).print();puts("");
    if(a<b) putchar('-'),(b-a).print(),puts("");
    else (a-b).print(),puts("");
    (a*b).print();puts("");
    (a/b).print();puts("");
    (a%b).print();puts("");
    return 0;
}
2022/1/24 21:08
加载中...