## 11042 - Complex, difficult and complicated

Moderator: Board moderators

temper_3243
Experienced poster
Posts: 105
Joined: Wed May 25, 2005 7:23 am

### 11042 - Complex, difficult and complicated

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.

temper_3243
Experienced poster
Posts: 105
Joined: Wed May 25, 2005 7:23 am
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;
}

``````

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
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".

fernando
New poster
Posts: 21
Joined: Sat Mar 18, 2006 8:21 pm
What's the approach or mathematical concept required to solve this problem?

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
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)

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
I used brute force and got Accepted in 0.000 seconds.
Ami ekhono shopno dekhi...
HomePage

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
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.

arsalan_mousavian
Experienced poster
Posts: 111
Joined: Mon Jan 09, 2006 6:19 pm
Location: Tehran, Iran
Contact:
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

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
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?)

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
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.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
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.``````
Ami ekhono shopno dekhi...
HomePage

Solaris
Learning poster
Posts: 99
Joined: Sun Apr 06, 2003 5:53 am
Contact:
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
Where's the "Any" key?

mrahman
New poster
Posts: 25
Joined: Mon Oct 24, 2005 9:45 am
Contact:
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
Practice Makes a man perfect

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)
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.

fh
Learning poster
Posts: 59
Joined: Wed Jan 19, 2005 3:24 pm
Location: Jakarta
Contact:
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
Visit my script to hunt UVA problem here:
http://felix-halim.net/uva/hunting/
-----------------------
Felix Halim