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

lame
New poster
Posts: 1
Joined: Sun Oct 15, 2006 2:14 pm

11121 - Base -2

Post by lame » Sun Oct 15, 2006 2:18 pm

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 ! :-?

User avatar
vinay
Experienced poster
Posts: 104
Joined: Thu Apr 13, 2006 2:26 pm
Location: India
Contact:

Post by vinay » Sun Oct 15, 2006 3:20 pm

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 .. :)
If I will myself do hashing, then who will do coding !!!

mrahman
New poster
Posts: 25
Joined: Mon Oct 24, 2005 9:45 am
Location: Bangladesh
Contact:

Post by mrahman » Mon Oct 16, 2006 4:14 am

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!!
Practice Makes a man perfect

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo » Tue Oct 17, 2006 10:16 am

Write down a base -2 expansion for an arbitrary number, then consider it mod 2.

Jared
New poster
Posts: 3
Joined: Wed Jul 20, 2005 11:50 am

Post by Jared » Tue Dec 05, 2006 10:50 am

I still don't understand. Can somebody give me some more hints? Thanks a lot.

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan » Tue Dec 05, 2006 3:01 pm

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 .....
Time that gone is gone forever ...

Jared
New poster
Posts: 3
Joined: Wed Jul 20, 2005 11:50 am

Post by Jared » Thu Dec 07, 2006 6:30 am

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!

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

it seems correct but judges said CE..?

Post by algoJo » Wed Dec 20, 2006 7:18 am

Code: Select all

Removed after AC-ed 
Thanks to helloneo..
Last edited by algoJo on Wed Dec 20, 2006 7:29 am, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Wed Dec 20, 2006 7:23 am

I got this message..

Code: Select all

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

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo » Wed Dec 20, 2006 7:28 am

wow... Thanks a lot helloneo :P
finally AC-ed

pvncad
New poster
Posts: 27
Joined: Sun Feb 18, 2007 2:14 pm

Post by pvncad » Tue Feb 20, 2007 11:31 am

I am using following functions to find the answer.

Can someone help me whats wrong with this code ?

Code: Select all

deleted
Last edited by pvncad on Thu Mar 08, 2007 3:42 pm, edited 1 time in total.

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo » Tue Feb 20, 2007 3:30 pm

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

pvncad
New poster
Posts: 27
Joined: Sun Feb 18, 2007 2:14 pm

Post by pvncad » Thu Mar 08, 2007 3:46 pm

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

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Fri Mar 09, 2007 11:31 am

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..

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

Post by lovemagic » Tue Jun 19, 2007 1:02 am

can somebody tell me where's my wrong?

Code: Select all


code removed...

Last edited by lovemagic on Tue Jun 19, 2007 11:45 pm, edited 1 time in total.
khobaib

Post Reply

Return to “Volume 111 (11100-11199)”