3 条题解

  • 0
    @ 2025-2-14 20:41:23
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <string>
    #include <boost/multiprecision/cpp_dec_float.hpp>
    
    using namespace std;
    using namespace boost::multiprecision;
    
    // 使用高精度浮点数类型(100位小数精度)
    using high_precision_float = cpp_dec_float_100;
    
    int main() {
        // 读取输入
        string input_data;
        getline(cin, input_data);
    
        // 分割输入
        size_t space_pos = input_data.find(' ');
        string R_str = input_data.substr(0, space_pos);
        string n_str = input_data.substr(space_pos + 1);
    
        // 转换 R 为高精度浮点数,n 为整数
        high_precision_float R(R_str);
        int n = stoi(n_str);
    
        // 计算 R 的 n 次方
        high_precision_float result = pow(R, n);
    
        // 将结果转换为字符串
        stringstream ss;
        ss << fixed << setprecision(100) << result;  // 设置足够高的精度
        string result_str = ss.str();
    
        // 去掉末尾的0以及小数点
        size_t dot_pos = result_str.find('.');
        if (dot_pos != string::npos) {
            result_str.erase(result_str.find_last_not_of('0') + 1, string::npos);
            if (result_str.back() == '.') {
                result_str.pop_back();
            }
        }
    
        // 如果结果是以 "0." 开头的小数,去掉开头的 0
        if (result_str.size() >= 2 && result_str[0] == '0' && result_str[1] == '.') {
            result_str.erase(0, 1);
        }
    
        // 输出结果
        cout << result_str << endl;
    
        return 0;
    }
    

    信息

    ID
    1192
    时间
    1000ms
    内存
    128MiB
    难度
    9
    标签
    递交数
    62
    已通过
    7
    上传者