11121 - Base -2

All about problems in Volume 111. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am

Post by hamedv » Tue Jun 19, 2007 5:23 am

In line 21 :
Change
for(k=1;k<ks;k++){
to
for(k=1;k<=ks;k++){

lovemagic
Learning poster
Posts: 52
Joined: Thu Oct 02, 2003 11:38 am

Post by lovemagic » Tue Jun 19, 2007 11:39 pm

yeah,i already got it.
thanx :lol:
khobaib

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

why 11121 Base -2WA

Post by bishop » Sat Jul 28, 2007 10:28 am

can anyone tell me why WA

Code: Select all



Last edited by bishop on Fri Aug 03, 2007 8:07 am, edited 1 time in total.

kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Location: Dhaka,Bangladesh
Contact:

Post by kolpobilashi » Thu Aug 02, 2007 5:36 pm

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
Sanjana

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 » Tue Feb 19, 2008 9:51 pm

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.
''I want to be most laziest person in the world''

deadangelx
New poster
Posts: 32
Joined: Tue Feb 13, 2007 1:31 pm

Re: 11121 - Base -2

Post by deadangelx » Fri Feb 13, 2009 9:44 am

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.

snape
New poster
Posts: 5
Joined: Sat Dec 03, 2011 4:18 pm

11121-Base -2

Post by snape » Fri Jan 06, 2012 1:11 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11121-Base -2

Post by brianfry713 » Fri Jan 13, 2012 1:53 am

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.
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11121 - Base -2

Post by uDebug » Tue Jul 08, 2014 8:30 am

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 111 (11100-11199)”