您的位置:首页 > 其它

算法提高 复数归一化

2014-05-23 15:58 239 查看
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代码:

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <vector>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma warning(disable:4786)

using namespace std;

const int INF = 0x3f3f3f3f;
const int Max = 10000 + 10;
const double eps = 1e-8;
const double PI = acos(-1.0);

int main()
{
float a , b;
scanf("%f%f",&a , &b);
printf("%.1f+%.1fi\n",a / sqrt(a * a + b * b) , b / sqrt(a * a + b * b));
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: