题意
给出了一个从整数到复数的映射,你要求出给你的整数映射成的复数的实部和虚部。
思路
STL complex裸题。
直接模拟就好,当然自己写一个complex结构体也不是难事。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> #include <stack> #include <cmath> #include <map> #include <complex> using namespace std; complex<long long> imo[33]; void pre(){ imo[0] = 1; for(int i = 1; i<= 32; i++){ imo[i] = imo[i-1] * complex<long long>(-1,1); } } int main(){ pre(); long long p; while(scanf(" %lld",&p) != EOF){ complex<long long> ans = 0; int cur = 0; while(p){ if(p & 1){ ans += imo[cur]; } cur++; p >>= 1; } printf("%lld %lld\n",ans.real(),ans.imag()); } return 0; } |