求第五点的数据

第五点始终过不了,不知道啥问题!!orz!!!

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
struct BigInt{
    static const int base = 100000000;
    static const int width = 8;
    vector<int> s;
    BigInt(const int &n=0){
        *this = n;
    }
    BigInt(const BigInt &b){
        *this = b;
    }
    BigInt(const string &a){
        *this = a;
    }
    BigInt& operator = (const long long &n){
        long long num = n;
        s.clear();
        while(num>0){
            s.push_back(num%base);
            num /= base;
        }
        return *this;
    }
    BigInt& operator = (const BigInt &b){
        s.clear();
        for(int i=0; i<b.s.size(); i++){
            s.push_back(b.s[i]);
        }
        return *this;
    }
    BigInt& operator = (const string &a){
        s.clear();
        int len = a.size(),st,ed,sum;
        for(int i=len; i>=0; i -= width){
            sum = 0;
            ed = i;
            st = max(0,i-width);
            for(int j=st;j<ed;j++){
                sum *= 10;
                sum += a[j] - '0';
            }
            s.push_back(sum);
        }
        return *this;
    }
    BigInt operator + (const int & b){
        return (*this)+(BigInt)b;
    }
    BigInt operator + (const BigInt &b){
        BigInt res;
        res.s.clear();
        int i=0,r,c=0;
        while(c!=0||i<s.size()||i<b.s.size()){
            r = c;
            c = 0;
            if(i<s.size()) r += s[i];
            if(i<b.s.size()) r += b.s[i];
            res.s.push_back(r%base);
            c = r/base;
            i++;
        }
        return res;
    }
    BigInt operator - (const BigInt &b){
        BigInt res;
        res.s.clear();
        int i=0,c=0,r;
        while(i<s.size()){
            r = c;
            c = 0;
            r += s[i];
            if(i<b.s.size()) r -= b.s[i];
            if(r<0){
                c = -1;
                r += base;
            }
            res.s.push_back(r);
            i++;
        }
        while(res.s.size()!=1 && res.s.back()==0) res.s.pop_back();
        return res;
    }
    BigInt operator * (const int &b){
        return (*this)*(BigInt)b;
    }
    BigInt operator * (const BigInt &b){
        BigInt res;
        res.s.resize(s.size()+b.s.size(),0);
        long long r;
        for(int i=0;i<s.size();i++){
            for(int j=0;j<b.s.size();j++){
                r = (long long)s[i]*b.s[j];
                res.s[i+j] += r%base;
                res.s[i+j+1] += r/base;
            }
        }
        for(int i=0;i<s.size()+b.s.size()-1;i++){
            res.s[i+1] += res.s[i]/base;
            res.s[i] = res.s[i]%base;
        }
        while(res.s.size()!=1 && res.s.back()==0) res.s.pop_back();
        return res;
    }
    BigInt operator / (const int &b){
        BigInt res = *this;
        int r,c=0;
        for(int i=s.size()-1;i>=0;i--){
            r = c*base+res.s[i];
            res.s[i] = r/b;
            c = r%b;
        }
        while(res.s.size()!=1 && res.s.back()==0) res.s.pop_back();
        return res;
    }
    bool operator <= (BigInt &b){
        if(s.size()!=b.s.size()) return s.size()<b.s.size();
        else{
            for(int i=s.size()-1;i>=0;i--){
                if(s[i]!=b.s[i]) return s[i]<b.s[i];
            }
        }
        return true;
    }
    bool operator == (BigInt &b){
        if(s.size()!=b.s.size()) return false;
        else{
            for(int i=s.size()-1;i>=0;i--) if(s[i]!=b.s[i]) return false;
        }
        return true;
    }
    friend ostream& operator << (ostream &out, const BigInt &b){
        out<<b.s.back();
        for(int i=b.s.size()-2;i>=0;i--){
            char buf[20];
            sprintf(buf,"%08d",b.s[i]);
            for(int j=0;j<strlen(buf);j++) out<<buf[j];
        }
        return out;
    }
};

int main(){
    string a;
    cin>>a;
    BigInt N=a,left=0,right=N,mid,res;
    while(1){
        mid = (left+right)/2;
        if(left == mid) break;
        res = mid*mid*mid+mid*mid+mid*3;
        if(res<=N) left = mid;
        else right = mid;
    }
    cout<<left;

    return 0;
}

0 条评论

目前还没有评论...

信息

ID
1375
难度
6
分类
高精度 | 其他 | 二分查找 点击显示
标签
(无)
递交数
947
已通过
276
通过率
29%
上传者