Welcome

首页 / 软件开发 / 数据结构与算法 / UVa 11042 Complex, difficult and complicated:一个常数很小的O(1)解决方法

UVa 11042 Complex, difficult and complicated:一个常数很小的O(1)解决方法2014-07-07http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1983

与复数的幂次有关的题,首先从几何角度考虑,一个复数能否绕原点逆时针旋转k*arctan(b/a)次后变为实数?(复数幂的几何性质)

(这里先特判一下,当a=0时,很明显,n=2)

要做到这一点,arctan(b/a)必须为有理数,而这篇文章表明,这一点当且仅当b/a∈{-1,0,1}时才成立。

所以,只要判断b/a是否∈{-1,0,1}就行了,其他的均为TOO COMPLICATED。

完整代码:

01./*0.013s*/02.03.#include<cstdio>04.#include<cstdlib>05.06.int main()07.{08.int t, a, b;09.scanf("%d", &t);10.while (t--)11.{12.scanf("%d%d", &a, &b);13.if (b == 0) puts("1");14.else if (a == 0) puts("2");15.else if (abs(a) == abs(b)) puts("4");16.else puts("TOO COMPLICATED");17.}18.return 0;19.}