Zerojudge b943:複數 の 指對數
Zerojudge b943:複數 の 指對數
題目大意:求 $z_1^{z_2}$ 或 $log_{z_1}(z_2)$
解法:$\text{complex}$
$\text{Code:}$
#pragma GCC optimize("O3")
#include <iostream>
#include <complex>
#include <cmath>
#include <iomanip>
#define LD long double
using namespace std;
int type;
void out (LD x, bool is) {
if (is == 1) {
if (-1e-10 < x && x < 1e-10) {
cout << " + 0.000000";
return;
}
if (x < 0) {
cout << " - ", x = -x;
} else {
cout << " + ";
}
cout << fixed << setprecision (6) << x;
} else {
if (-1e-10 < x && x < 1e-10) {
cout << "0.000000";
return;
}
if (x < 0) {
cout << '-', x = -x;
}
cout << fixed << setprecision (6) << x;
}
}
void solve() {
complex<LD>z1, z2;
LD a, b;
cin >> a >> b;
z1 = {a, b};
cin >> a >> b;
z2 = {a, b};
if (type == 1) {
z1 = pow (z1, z2);
} else {
z1 = log (z2) / log (z1);
}
out (z1.real(), 0);
out (z1.imag(), 1);
cout << "i\n";
}
int main() {
ios::sync_with_stdio (false), cin.tie (0);
while (cin >> type && type)
solve();
}
我的分享就到這裡結束了,如果喜歡我的 $\text{Blog}$,歡迎追蹤!
留言
張貼留言