作者已疯RE0qwq

image

#include<bits/stdc++.h>
using namespace std;
string a1,b1;
int n;
string sum[1001];
string aa;
vector<int>sum1,ans1;
struct node{
    int z,y;
}a[1001];
bool cmp(node a,node b){
    return a.z<b.z;
}
void cheng(string aa,unsigned long long b){
    int c[1001],f[1001];
    int n=aa.length();
    for(int i=0;i<n;i++) c[i]=aa[n-i-1]-'0';
    for(int i=0;i<n;i++){
        sum1[i]=sum1[i]+(sum1[i]*b);
        sum1[i+1]+=sum1[i]/10;
        sum1[i]%=10;
    }
}
void chu(string aaa,unsigned long long bb){
    memset(sum,0,sizeof(sum));
    int x=0;
    for(int i=0;i<n;i++){
        x=x*10+(aaa[i]-'0');
        sum1[i]=x/bb;
        x%=bb;
    }
}
bool ma(vector<int>a,vector<int>b){
    if(a.size()!=b.size()) return a.size()>b.size();
    for(int i=0;i<a.size();i++) if(a[i]!=b[i]) return a[i]>b[i]; 
}
int main(){
    cin>>n>>a1>>b1;
    for(int i=1;i<=n;i++) cin>>a[i].z>>a[i].y;
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        cheng(sum[i-1],a[i].z);
        chu(sum[i-1],a[i].y);
        if(ma(sum1,ans1)) for(int i=0;i<n;i++) ans1[i]=sum1[i];
    }
    for(int i=0;i<n;i++) cout<<ans1[i];
}

应该是这错了:
sum1[i]=sum1[i]+(sum1[i]*b);

九敏,九敏!

你的高精度是对的吗

应该是错的…但我不会调

abab

问AI

a???????

AI写的就是shǐ

@连晨皓 你确定是高精度错了吗?

AI说的

    // 按照贪心策略排序
    sort(ministers.begin(), ministers.end());
    
    BigInt product = king_left;  // 乘积初始为国王左手数字
    BigInt max_coins;            // 最大金币数
    max_coins = 0;
    
    for (int i = 0; i < n; i++) {
        BigInt coins = product / ministers[i].right;
        if (coins > max_coins) {
            max_coins = coins;
        }
        product *= ministers[i].left;
    }
    
    max_coins.print();

确定

shǐ,没法看

// 高精度乘法:大数(字符串表示) * 整数
vector<int> cheng(const string& num, unsigned long long b) {
    vector<int> result;
    if (b == 0) {
        result.push_back(0);
        return result;
    }
    
    // 将字符串转换为逆序数字数组
    vector<int> digits;
    for (int i = num.length() - 1; i >= 0; i--) {
        digits.push_back(num[i] - '0');
    }
    
    // 执行乘法运算
    int carry = 0;
    for (int i = 0; i < digits.size(); i++) {
        long long product = (long long)digits[i] * b + carry;
        result.push_back(product % 10);
        carry = product / 10;
    }
    
    // 处理最终的进位
    while (carry > 0) {
        result.push_back(carry % 10);
        carry /= 10;
    }
    
    // 移除前导零
    while (result.size() > 1 && result.back() == 0) {
        result.pop_back();
    }
    
    return result;
}

// 高精度除法:大数(字符串表示) / 整数
vector<int> chu(const string& num, unsigned long long divisor) {
    if (divisor == 0) {
        cerr << "错误:除数不能为0" << endl;
        return vector<int>(1, 0);
    }
    
    vector<int> result;
    long long remainder = 0;
    
    // 从高位到低位逐位进行除法
    for (int i = 0; i < num.length(); i++) {
        remainder = remainder * 10 + (num[i] - '0');
        result.push_back(remainder / divisor);
        remainder %= divisor;
    }
    
    // 反转结果并移除前导零
    reverse(result.begin(), result.end());
    while (result.size() > 1 && result[0] == 0) {
        result.erase(result.begin());
    }
    
    return result;
}

// 辅助函数:将vector<int>转换为字符串
string vectorToString(const vector<int>& v) {
    string result;
    for (int digit : v) {
        result = to_string(digit) + result;  // 注意这里是倒序
    }
    return result.empty() ? "0" : result;
}

分析:
image

#include<bits/stdc++.h>
using namespace std;
string a1,b1;
int n;
string sum[1001];
string aa;
vector<unsigned long long>sum1(1005),ans1(1005);
struct node{
    int z,y;
}a[1001];
bool cmp(node a,node b){
    return a.z<b.z;
}
void cheng(string aa,unsigned long long b){
    int c[1001]{0};
    int n=aa.length();
    for(int i=0;i<n;i++) c[i]=aa[n-i-1]-'0';
    for(int i=0;i<n;i++){
        sum1[i]+=(c[i]*b);
        sum1[i+1]+=sum1[i]/10;
        sum1[i]%=10;
    }
}
void chu(string aaa,unsigned long long bb){
    sum1.clear();
    unsigned long long x=0;
    for(int i=0;i<n;i++){
        x=x*10+(aaa[i]-'0');
        sum1[i]=x/bb;
        x%=bb;
    }
}
bool ma(vector<unsigned long long>a,vector<unsigned long long>b){
    if(a.size()!=b.size()) return a.size()>b.size();
    for(int i=0;i<a.size();i++) if(a[i]!=b[i]) return a[i]>b[i]; 
}
int main(){
    cin>>n>>a1>>b1;
    for(int i=1;i<=n;i++) cin>>a[i].z>>a[i].y;
    sort(a+1,a+n+1,cmp);
    sum[0]=a1;
    for(int i=1;i<=n;i++){
        cheng(sum[i-1],a[i].z);
        chu(sum[i-1],a[i].y);
        if(ma(sum1,ans1)) for(int i=0;i<n;i++) ans1[i]=sum1[i];
    }
    for(int i=0;i<n;i++) cout<<ans1[i];
}

好了,WA了

还是0分

:face_with_raised_eyebrow:

咋了

@连晨皓 确定是吧,好的,给你个东西,高精度模板,含几乎所有的运算

没事了

@连晨皓

namespace BigINT{
    #define digit int
    #define ull unsigned long long
    #define ll long long
    class bigInt {digit *value;ull capacity;ull length;bool sign;private:inline void Genshin_Impact_start();inline void emplace_back(const digit &new_digit);inline void put_string(std::string from);inline void put_bigInt(const bigInt &from);inline void put_ull_interger(ull from, const bool &new_sign = 0);inline void put_ll_interger(const ll &from);inline void pop_zero();inline void negation();inline digit at(const int &idx) const;public:void reserve(ull new_cap);bigInt& operator =(const bigInt &from);bigInt& operator =(std::string from);bigInt& operator =(const ull &from);bigInt& operator =(const ll &from);bigInt& operator =(const unsigned int &from);bigInt& operator =(const int &from);bigInt() { Genshin_Impact_start(); }bigInt(std::string str) { put_string(str); }bigInt(const ull &from) { put_ull_interger(from, 0); }bigInt(const ll &from) { put_ll_interger(from); }bigInt(const unsigned int &from) { put_ull_interger(from, 0); }bigInt(const int &from) { put_ll_interger(from); }~bigInt() {delete[] value;}friend std::ostream& operator<<(std::ostream& out, const bigInt &num) {if (num.length == 0) {out << '0';return out;}if (num.sign == 1) out << '-';for (int idx = (num.length) - 1; idx >= 0; --idx) out << char(num.value[idx] + 48);return out;}friend std::istream& operator>>(std::istream& in, bigInt &num) {num.Genshin_Impact_start();char ch = in.get();while (ch < '0' || ch > '9') {if (ch == '-') num.sign = 1;ch = in.get();}while (ch >= '0' && ch <= '9') {num.emplace_back(ch ^ 48);ch = in.get();}for (int l = 0, r = num.length - 1; l < r; ++l, --r) std::swap(num.value[l], num.value[r]);num.pop_zero();return in;}inline ull size();inline ll to_digit();inline std::string to_string();inline bool operator==(const bigInt &other) const;inline bool operator<(const bigInt &other) const;inline bool operator>(const bigInt &other) const;inline bool operator<=(const bigInt &other) const;inline bool operator>=(const bigInt &other) const;inline bool operator!=(const bigInt &other) const;inline bigInt operator<<(const int &num);inline bigInt operator>>(const int &num);inline bigInt operator-() const;inline bigInt operator+(bigInt other);inline bigInt operator-(bigInt other);inline bigInt operator*(bigInt other);inline bigInt operator/(bigInt other);inline bigInt operator%(bigInt other);inline bigInt operator&(bigInt other);inline bigInt operator|(bigInt other);inline bigInt &operator<<=(const int &num);inline bigInt &operator>>=(const int &num);inline bigInt &operator+=(const bigInt &other);inline bigInt &operator-=(const bigInt &other);inline bigInt &operator*=(const bigInt &other);inline bigInt &operator/=(const bigInt &other);inline bigInt &operator%=(const bigInt &other);inline bigInt &operator&=(const bigInt &other);inline bigInt &operator|=(const bigInt &other);bigInt& operator++();bigInt operator++(int);bigInt& operator--();bigInt operator--(int);};inline void bigInt::Genshin_Impact_start() {this->sign = 0;this->capacity = 1;this->length = 0;this->value = new digit[1];this->reserve(-1);}void bigInt::reserve(ull new_cap = -1) {if (new_cap == -1) new_cap = (this->capacity) << 1;digit *past_value = this->value;this->capacity = new_cap;this->value = new digit[this->capacity];for (int idx = 0; idx < (this->length); ++idx) value[idx] = past_value[idx];for (int idx = (this->length); idx < new_cap; ++idx) { value[idx] = 0; }delete[] past_value;}inline void bigInt::put_string(std::string from) {this->Genshin_Impact_start();if (from.front() == '-') {sign = 1;from = from.substr(1);}for (const char &to_put : from) {this->emplace_back(to_put ^ 48);}for (int l = 0, r = this->length - 1; l < r; ++l, --r) std::swap(value[l], value[r]);this->pop_zero();}inline void bigInt::put_bigInt(const bigInt &from) {this->Genshin_Impact_start();for (int idx = 0; idx < from.length; ++idx) this->emplace_back(from.value[idx]);this->sign = from.sign;}inline void bigInt::put_ull_interger(ull from, const bool &new_sign) {this->Genshin_Impact_start();this->sign = new_sign;while (from) {this->emplace_back(from % 10);from /= 10;}this->pop_zero();}inline void bigInt::put_ll_interger(const ll &from) {if (from < 0) this->put_ull_interger((ull)-from, 1);else this->put_ull_interger(from, 0);}inline void bigInt::emplace_back(const digit &new_digit) {if ((this->length) == (this->capacity)) this->reserve();this->value[(this->length)++] = new_digit;}inline void bigInt::pop_zero() {while (length && this->value[length - 1] == 0) {--length;if (length == (capacity >> 1)) reserve(capacity >> 1);}}inline void bigInt::negation() { this->sign = !(this->sign); }inline digit bigInt::at(const int &idx) const {if (idx < length) return value[idx];else return 0;}bigInt &bigInt::operator=(const bigInt &from) { this->put_bigInt(from); return *this; }bigInt &bigInt::operator=(std::string from) { this->put_string(from); return *this; }bigInt &bigInt::operator=(const ull &from) { put_ull_interger(from, 0); return *this; }bigInt &bigInt::operator=(const ll &from) { put_ll_interger(from); return *this; }bigInt &bigInt::operator=(const unsigned int &from) { put_ull_interger(from, 0); return *this; }bigInt &bigInt::operator=(const int &from) { put_ll_interger(from); return *this; }inline ull bigInt::size() { return this->length; }inline ll bigInt::to_digit() {ll ans = 0, weight = 1;for (int i = 0; i < length; ++i) {ans += value[i] * weight;weight *= 10;}return (sign ? (-ans) : ans);}inline std::string bigInt::to_string() {std::string ans;if (sign) ans.push_back('-');for (int i = length - 1; i >= 0; --i) ans.push_back(value[i] + '0');return ans;}inline bool bigInt::operator==(const bigInt &other) const {if (this->length != other.length || this->sign != other.sign) return false;for (int idx = 0; idx < (this->length); ++idx) {if (this->value[idx] != other.value[idx]) return false;}return true;}inline bool bigInt::operator<(const bigInt &other) const {if (this->sign == 1 && other.sign == 0) return true;else if (this->sign == 0 && other.sign == 1) return false;else if (this->sign == 1 && other.sign == 1) return -(*this) > -other;if (this->length < other.length) return true;if (this->length > other.length) return false;for (int idx = (this->length) - 1; idx >= 0; --idx) {if (this->value[idx] > other.value[idx]) return false;if (this->value[idx] < other.value[idx]) return true;}return false;}inline bool bigInt::operator>(const bigInt &other) const {if (this->sign == 1 && other.sign == 0) return false;else if (this->sign == 0 && other.sign == 1) return true;else if (this->sign == 1 && other.sign == 1) return -(*this) < -other;if (this->length > other.length) return true;else if (this->length < other.length) return false;for (int idx = (this->length) - 1; idx >= 0; --idx) {if (this->value[idx] < other.value[idx]) return false;if (this->value[idx] > other.value[idx]) return true;}return false;}inline bool bigInt::operator<=(const bigInt &other) const { return !((*this) > other); }inline bool bigInt::operator>=(const bigInt &other) const { return !((*this) < other); }inline bool bigInt::operator!=(const bigInt &other) const { return !((*this) == other); }inline bigInt bigInt::operator<<(const int &num) {bigInt ans;ans.reserve(length + num);ans.length = ans.capacity;for (int i = 0; i < num; ++i) ans.value[i] = 0;for (int i = 0; i < length; ++i) ans.value[i + num] = value[i];ans.pop_zero();return ans;}inline bigInt bigInt::operator>>(const int &num) {if ((this->length) <= num) return bigInt();bigInt ans;ans.reserve(length - num);ans.length = ans.capacity;for (int i = num; i < length; ++i) ans.value[i - num] = value[i];ans.pop_zero();return ans;}inline bigInt bigInt::operator-() const {bigInt ans = (*this);ans.negation();return ans;}inline bigInt bigInt::operator+(bigInt other) {if (this->sign != other.sign) {if (this->sign == 1) {if (-(*this) > other) return -(-(*this) - other);else return other - (-(*this));}else if (this->sign == 0) {if ((*this) > -other) return (*this) - (-other);else return -(-other - (*this));}}if (other == 0) return (*this);bigInt ans;ans.reserve(std::max(other.length, this->length) + 1);ans.length = ans.capacity;for (int idx = 0; idx < ans.length; ++idx) {ans.value[idx] += this->at(idx) + other.at(idx);if (ans.value[idx] >= 10) {++ans.value[idx + 1];ans.value[idx] -= 10;}}ans.pop_zero();ans.sign = this->sign;return ans;}inline bigInt bigInt::operator-(bigInt other) {if (this->sign || other.sign) {if (this->sign == 0 && other.sign == 1) return (*this) + (-other);if (this->sign == 1) {if (other.sign == 0) {return -(-(*this) + other);}else {return (*this) + (-other);}}}if (other == 0) return (*this);if ((*this) < other) return -(other - (*this));bigInt ans;ans.reserve(this->length);ans.length = ans.capacity;for (int idx = 0; idx < (this->length); ++idx) {ans.value[idx] += this->at(idx) - other.at(idx);if (ans.value[idx] < 0) {--ans.value[idx + 1];ans.value[idx] += 10;}}return ans;}inline bigInt bigInt::operator*(bigInt other) {bigInt ans;int now;ans.reserve(this->length + other.length);ans.length = ans.capacity;for (int idx_this = 0; idx_this < (this->length); ++idx_this) {for (int idx_other = 0; idx_other < other.length; ++idx_other) {now = idx_this + idx_other;ans.value[now] += (this->at(idx_this)) * other.at(idx_other);if (ans.value[now] >= 10) {ans.value[now + 1] += (ans.value[now]) / 10;ans.value[now] %= 10;}}}ans.pop_zero();ans.sign = (this->sign) != other.sign;return ans;}inline bigInt bigInt::operator/(bigInt other) {if (other == bigInt(0)) {std::cerr << "Error: Divide by zero!" << std::endl;throw std::invalid_argument("Divide by zero!");}else if ((*this) == bigInt(0)) return 0;else if ((*this) < other) return 0;bigInt ans, cur, divi = (*this);int l, r, mid;ans.reserve((this->length) - other.length + 1);ans.length = ans.capacity;for (int idx = ans.length - 1; idx >= 0; --idx) {cur = divi >> idx;l = 0, r = 9;while (l < r) {mid = l + r + 1 >> 1;if (other * mid <= cur) l = mid;else r = mid - 1;}mid = l;ans.value[idx] = l;divi = divi - ((other * mid) << idx);divi.pop_zero();}ans.pop_zero();ans.sign = (this->sign) != other.sign;return ans;}inline bigInt bigInt::operator%(bigInt other) {if (other == bigInt(0)) {std::cerr << "Error: Divide by zero!" << std::endl;throw std::invalid_argument("Divide by zero!");}else if ((*this) == bigInt(0)) return 0;bigInt cur, divi = (*this);int l, r, mid;for (int idx = ((this->length) - other.length); idx >= 0; --idx) {cur = divi >> idx;l = 0, r = 9;while (l < r) {mid = l + r + 1 >> 1;if (other * mid <= cur) l = mid;else r = mid - 1;}mid = l;divi = divi - (other * mid << idx);divi.pop_zero();}return divi;}inline bigInt &bigInt::operator<<=(const int &num) { return ((*this) = (*this) << num); }inline bigInt &bigInt::operator>>=(const int &num) { return ((*this) = (*this) >> num); }inline bigInt &bigInt::operator+=(const bigInt &num) { return ((*this) = (*this) + num); }inline bigInt &bigInt::operator-=(const bigInt &num) { return ((*this) = (*this) - num); }inline bigInt &bigInt::operator*=(const bigInt &num) { return ((*this) = (*this) * num); }inline bigInt &bigInt::operator/=(const bigInt &num) { return ((*this) = (*this) / num); }inline bigInt &bigInt::operator%=(const bigInt &num) { return ((*this) = (*this) % num); }inline bigInt bigInt::operator&(bigInt other) {bigInt ans;ans.reserve(std::max(this->length, other.length));ans.length = ans.capacity;for (int i = 0; i < ans.length; ++i) {ans.value[i] = this->at(i) & other.at(i);}ans.pop_zero();ans.sign = this->sign & other.sign;return ans;}inline bigInt bigInt::operator|(bigInt other) {bigInt ans;ans.reserve(std::max(this->length, other.length));ans.length = ans.capacity;for (int i = 0; i < ans.length; ++i) {ans.value[i] = this->at(i) | other.at(i);}ans.pop_zero();ans.sign = this->sign | other.sign;return ans;}inline bigInt &bigInt::operator&=(const bigInt &other) {return (*this = *this & other);}inline bigInt &bigInt::operator|=(const bigInt &other) {return (*this = *this | other);}bigInt& bigInt::operator++() {*this += bigInt(1);return *this;}bigInt bigInt::operator++(int) {bigInt temp = *this;++(*this);return temp;}bigInt& bigInt::operator--() {*this -= bigInt(1);return *this;}bigInt bigInt::operator--(int) {bigInt temp = *this;--(*this);return temp;}
}using namespace BigINT;

建议在后面加一个 define int bigInt 这样你写 int 就自动默认是高精度