Page 2 of 2

Posted: Tue Jun 19, 2007 5:23 am
by hamedv
In line 21 :
Change
for(k=1;k<ks;k++){
to
for(k=1;k<=ks;k++){

Posted: Tue Jun 19, 2007 11:39 pm
by lovemagic
yeah,i already got it.
thanx :lol:

why 11121 Base -2WA

Posted: Sat Jul 28, 2007 10:28 am
by bishop
can anyone tell me why WA

Code: Select all




Posted: Thu Aug 02, 2007 5:36 pm
by kolpobilashi
check ur code for these input:

Code: Select all

5

8
9
-9
-11
-13
correct output will be:

Code: Select all

11000
11001
1011
110101
110111
best of luck TD! :D

Posted: Tue Feb 19, 2008 9:51 pm
by turcse143
pvncad, ur code looking good,
i got AC by using the recursion algorithem.
simple comparing the numbers.
use this example:
Keep in mind this simple algerbraic formula: if a / b = c remainder d, then bc + d = a.

Thus, to expand decimal 2 in negabinary:

2 / -2 = -1 remainder 0
-1 / -2 = 1 remainder 1
1 / -2 = 0 remainder 1


Taking those remainders in reverse order we get 110. So 110 is the negabinary representation of decimal 2.
hope it helps.

Re: 11121 - Base -2

Posted: Fri Feb 13, 2009 9:44 am
by deadangelx
test cases

Code: Select all

4
1000000000
-1000000000
1024
-1024
answer

Code: Select all

Case #1: 1001100111011111101111000000000
Case #2: 11000101101001010100101000000000
Case #3: 10000000000
Case #4: 110000000000
hope it helps.

11121-Base -2

Posted: Fri Jan 06, 2012 1:11 pm
by snape
11121,plz help. after hard work i code this,bt get TLE && thn RE
if anyone can tell me if i will need to change my logic,thn i will.
if any one can tell me in this logic how i recover this RE & TLE.

my code is here:

#include <stdio.h>
#include <math.h>
#define N 2000000
#include <string.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long int d=-2,e=2,n,b,z,i,sum=0,c,r=0;
char a[N];
int main()
{
//d=-2;
//e=2;
scanf("%lld",&n);
getchar();
while(r<n)
{
scanf("%lld",&b);

z=b;

i=0;

if(i==0)
{
if(b%2==0)
{
a='0';

c=0;

sum+=(a-48);

i++;

}
else{
a='1';

c=1;

sum+=(a-48);

i++;

}
}


while(1)
{
if(sum==z)
break;

if(b>0)
{
b=(b-c)/d;

if(b%2!=0)
{
a='1';

c=1;

sum+=((a-48)*pow(d,i));

i++;
}
else{
a='0';
c=0;
sum+=((a-48)*pow(d,i));

i++;

}
}

if(b<0)
{
b=(b-c)/e;

if(b%2!=0)
{
a='1';

c=1;

sum+=((a-48)*pow(d,i));

i++;

}
else{
a[i]='0';

c=0;

sum+=((a[i]-48)*pow(d,i));

i++;

}
}

}
i=i-1;
printf("Case #%lld: ",r+1);
reverse(a,a+strlen(a));
printf("%s",a);

if(r<(n-1))
printf("\n");
r++;

sum=0;
}

return 0;
}

Re: 11121-Base -2

Posted: Fri Jan 13, 2012 1:53 am
by brianfry713
Use the existing thread. Use the code blocks.

Your program fails for the sample input and you also don't print a newline after the last case. It looks like you're not re-initializing all your variables.

Re: 11121 - Base -2

Posted: Tue Jul 08, 2014 8:30 am
by uDebug
Replying to follow the thread.