Page 1 of 2

11042 - Complex, difficult and complicated

Posted: Sun Jun 04, 2006 6:40 pm
by temper_3243
hi,
Does anyone have testcases for the problem 11042. When i submit the code, the problem says received but nothing about status.


Can someone post good test cases.

Posted: Mon Jun 05, 2006 12:44 am
by temper_3243
HI,
I am getting WA. Can some one tell me where i am doiing things wrong .

Code: Select all

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

# define M_PI		3.14159265358979323846	/* pi */

double sqrt(double );
double atan(double );
double fabs(double );

int main()
{
       int i,a,b,no,k;
       double  m,n,z;

       scanf(" %d",&no);
       while(no--)
       {
               scanf(" %d %d",&a,&b);

               z=sqrt(a*a + b*b);

               if(a==0)
                       m=M_PI/2;
               else
                       m=atan((double)b/(double)a);

               if(m==0)
               {
                       printf("1\n");
                       continue;
               }

               k=fabs(M_PI/m);

               if (fabs(fabs(k*m ) - M_PI) < 0.00009)
		{
			if(pow(z,k) <= pow(2,30))
                       printf("%d\n",k);
		else
                       printf("TOO COMPLICATED\n");
		}
               else
                       printf("TOO COMPLICATED\n");
       }
       return 0;
}




Posted: Mon Jun 05, 2006 2:37 am
by mf
Here are some inputs for which your program gave wrong answer (at least, on my computer):

Code: Select all

5
0 0
-153 -265
-153 265
-97 -168
97 168
Correct answer for the first case is 1, for the rest -- "TOO COMPLICATED".

Posted: Mon Jun 05, 2006 3:45 am
by fernando
What's the approach or mathematical concept required to solve this problem?

Posted: Mon Jun 05, 2006 6:27 am
by Darko
This is the top Google link:
http://www.clarku.edu/~djoyce/complex/

The program above uses "polar coordinates", I solved it using cartesian coordinates ("complex plane"). (check the corresponding parts in that tutorial)

Posted: Mon Jun 05, 2006 4:51 pm
by Jan
I used brute force and got Accepted in 0.000 seconds.

Posted: Tue Jun 06, 2006 8:25 am
by shamim
Jan wrote:I used brute force and got Accepted in 0.000 seconds.
Is the solution simply to loop over N and stop when the number becomes real. If so, when should the looping stop if there is no solution.

Posted: Tue Jun 06, 2006 8:49 am
by arsalan_mousavian
shamim wrote:
Jan wrote:I used brute force and got Accepted in 0.000 seconds.
Is the solution simply to loop over N and stop when the number becomes real. If so, when should the looping stop if there is no solution.
Not exactly , you nead a condition to stop the loop ( for the case that the result is TOO COMPLICATED ) but the rest is completely brute force
hope it helps

Posted: Tue Jun 06, 2006 8:49 am
by Darko
I picked n=1000 and it worked. One could probably come up with a case that breaks it. (hm, maybe not - a,b are integers and they'll end up being > 2^30 really fast... silly me.. why did I pick such a high number?)

Posted: Tue Jun 06, 2006 3:03 pm
by shamim
Darko wrote:I picked n=1000 and it worked. One could probably come up with a case that breaks it. (hm, maybe not - a,b are integers and they'll end up being > 2^30 really fast... silly me.. why did I pick such a high number?)

I choose 100 and got AC.

Is it always true, as n increases the abs(real) part will also increase. Since i*i is -1, shouldn't at times, the real part decrease or something.

Posted: Tue Jun 06, 2006 3:33 pm
by Jan
Spoiler

My method is -

Code: Select all

Suppose a and b given...
I considered x=1 and y=0

1. I have two complex numbers -

P = x + iy
Q = a + ib

2. Every time multiply P and Q and update x, y (x, y to srore the multiplication results. x contains real part and y contains complex part) .

3. If abs (x) > 2^30 then TOO COMPLICATED. End.

4. If y = 0, Got the Solution. End.

5. Goto step 1.

Posted: Tue Jun 06, 2006 5:40 pm
by Solaris
When you convert the number to polar form ... then

SPOILER
(a+ib)^n
= r^n (cos (n.t) + i sin (n.t) )

You can safely say that if r^n is greater than 2^30 then TOO COMPLICATED

Posted: Fri Jun 09, 2006 5:25 am
by mrahman
Hi guys,

Spoiler

I think there can not be any input which output is greater than 4.
There is only 4 Possible output for the problem
1. 1
2. 2
3. 4
4. TOO COMPLICATED

Try to categorize all the input into 4 partition and you can solve it using only few If-else.

No need to use any loop
No need to use any cos or sin function

Sorry for my poor english

Take care

Posted: Sun Jun 11, 2006 2:23 am
by Martin Macko
mrahman wrote:Try to categorize all the input into 4 partition and you can solve it using only few If-else.

No need to use any loop
No need to use any cos or sin function
You are absolutelly right... After experiencing a few numbers by hand one can easily find those categories.

Posted: Fri Sep 22, 2006 5:30 pm
by fh
I think there can not be any input which output is greater than 4.
There is only 4 Possible output for the problem
1. 1
2. 2
3. 4
4. TOO COMPLICATED
I don't think so... for the input:

1
96 32

the output is

12