Page 1 of 2

11121 - Base -2

Posted: Sun Oct 15, 2006 2:18 pm
by lame
Hello , please give me a hint . I know that negative binary numbers are the binary number + a number 1 at the beginning , but it is not in this case. I suppose it's an easy problem , because noone didn't ask about it in the forum , but I just can't get it. :oops: It's embarassing not to see the easy problems sometimes but I still want to know the solution.
Thanks in advance ! :-?

Posted: Sun Oct 15, 2006 3:20 pm
by vinay
what if the number positive or negative is odd... what will be there at last place ...

after that how can we apply this process recursively..

think about it and solution is in front of u .. :)

Posted: Mon Oct 16, 2006 4:14 am
by mrahman
Hello Lame,

Think about Simply Binary number System

Code: Select all

           16  8  4  2  1        
   6 =            1  1  0

and negative 2 (-2) base System

           16  -8  4  -2  1
   6 =      1   1  0   1  0
good luck!!

Posted: Tue Oct 17, 2006 10:16 am
by sclo
Write down a base -2 expansion for an arbitrary number, then consider it mod 2.

Posted: Tue Dec 05, 2006 10:50 am
by Jared
I still don't understand. Can somebody give me some more hints? Thanks a lot.

Posted: Tue Dec 05, 2006 3:01 pm
by sakhassan
a number with base b can be expanded as follows :
n = m/b + r, where n= original number, r = reminder and m= what u need to find recursively .....

Posted: Thu Dec 07, 2006 6:30 am
by Jared
sakhassan wrote:a number with base b can be expanded as follows :
n = m/b + r, where n= original number, r = reminder and m= what u need to find recursively .....
Thanks for your hint! I got AC now!

it seems correct but judges said CE..?

Posted: Wed Dec 20, 2006 7:18 am
by algoJo

Code: Select all

Removed after AC-ed 
Thanks to helloneo..

Posted: Wed Dec 20, 2006 7:23 am
by helloneo
I got this message..

Code: Select all

array subscript is not an integer
So try to change the type of all 'i' to "int"

Posted: Wed Dec 20, 2006 7:28 am
by algoJo
wow... Thanks a lot helloneo :P
finally AC-ed

Posted: Tue Feb 20, 2007 11:31 am
by pvncad
I am using following functions to find the answer.

Can someone help me whats wrong with this code ?

Code: Select all

deleted

Posted: Tue Feb 20, 2007 3:30 pm
by algoJo
hi pvncad
try to change your data type from

Code: Select all

long long n
to

Code: Select all

long double n
and don't forget to remove your code after accepted... :D

Posted: Thu Mar 08, 2007 3:46 pm
by pvncad
Thanks. But now it is dying with signal 11. Though, it is running file for my test cases.
please give some inputs or let me know problem with following code.

Code: Select all

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

void print_binary(long double n)
{
  long double n1 = n / -2;
  int r;
  n = ceill(n1);
  if (n == n1) {
      r = 0;
  }
  else {
      r = 1;
  }
  if (n) {
      print_binary(n);
  }
  printf("%d", r);
}


int main()
{
  int N, count;
  long double n;
  count = 1;
  scanf("%d", &N);
  while (N --) {
      scanf("%Lf", &n);
      printf("Case #%d: ", count);
      print_binary(n);
      printf("\n");
      count ++;
  }
  return 0;
}
thanks

Posted: Fri Mar 09, 2007 11:31 am
by helloneo
Give EPS when you compare floating point numbers..
Try this..

Code: Select all

  if (n < 0.000001 && n > -0.000001) { 
      print_binary(n); 
  } 
Now you will get WA..

Posted: Tue Jun 19, 2007 1:02 am
by lovemagic
can somebody tell me where's my wrong?

Code: Select all


code removed...