3 条题解
-
0
#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; }
-
-2
#include<iostream> #include<bits/stdc++.h> using namespace std; int ans[200]; int Get[10]; char Cin[10]; int mul; void func(){ int temp[200] = {0}; for(int i = 1; i <= ans[0]; ++i){ for(int j = 1; j <= Get[0]; ++j){ temp[i+j-1] += ans[i]*Get[j]; temp[i+j] += temp[i+j-1] / 10; temp[i+j-1] = temp[i+j-1] % 10; } } int num = ans[0]+Get[0]; while(temp[num] == 0)num--; ans[0] = num; for(int i = 1; i <= num; ++i)ans[i] = temp[i]; return ; } int main(){ while(cin >> Cin >> mul){ int num = 1; int pos = -1; int flag = 0; if(Cin[0] == '0')flag = 1; for(int i = strlen(Cin) - 1; i >= 0; --i){ if(Cin[i] == '.'){ pos = strlen(Cin) - i; continue; } Get[num++] = Cin[i] - '0'; } if(pos == -1)pos = 1,Get[0] = strlen(Cin); else Get[0] = strlen(Cin) - 1; ans[0] = Get[0]; for(int i = 1; i <= Get[0]; ++i)ans[i] = Get[i]; for(int i = 1; i < mul; ++i){ func(); } int l = 1,r = ans[0]; while(ans[l] == 0 && l <= (pos-1)*mul)l++; if(flag){ cout << "0."; for(int i = (strlen(Cin)-2)*mul; i >= l; --i){ if(i > ans[0])cout << 0; else cout << ans[i]; } cout << endl; } else{ for(int i = r; i >= l; --i){ if(i == (pos-1) * mul)cout << '.'; cout << ans[i]; } cout << endl; } memset(ans,0,sizeof(ans)); memset(Get,0,sizeof(Get)); } return 0; }
- 1
信息
- ID
- 1192
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- 递交数
- 62
- 已通过
- 7
- 上传者