算法提高 复数归一化

http://lx.lanqiao.org/problem.page?gpid=T203

 算法提高 复数归一化  
时间限制:1.0s   内存限制:512.0MB
    
  编写函数Normalize,将复数归一化,即若复数为a+bi,归一化结果为a/sqrt(a*a+b*b) + i*b/sqrt(a*a+b*b) 。使用结构体指针类型作为函数参数可能是必要的。其中实部和虚部由键盘输入,输出为归一化结果,如果归一化结果的实部或虚部为小数的要求保留一位小数。
  样例输入:(格式说明:3 4 分别为以空格隔开的实数的实部和虚部)
  3 4
样例输出
0.6+0.8i
样例输入
2 5
样例输出
0.4+0.9i
 
分析:
可以不用题目所说的什么限定函数,可以直接输出。
 
AC代码:
 
 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <string.h>
 5 #include <string>
 6 #include <math.h>
 7 #include <stdlib.h>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <map>
12 #include <list>
13 #include <iomanip>
14 #include <vector>
15 #pragma comment(linker, "/STACK:1024000000,1024000000")
16 #pragma warning(disable:4786)
17 
18 using namespace std;
19 
20 const int INF = 0x3f3f3f3f;
21 const int Max = 10000 + 10;
22 const double eps = 1e-8;
23 const double PI = acos(-1.0);
24 
25 int main()
26 {
27     float a , b;
28     scanf("%f%f",&a , &b);
29     printf("%.1f+%.1fi
",a / sqrt(a * a + b * b) , b / sqrt(a * a + b * b));
30     return 0;
31 }
View Code
原文地址:https://www.cnblogs.com/jeff-wgc/p/4450799.html