Page 2 of 2

Posted: Tue Dec 19, 2006 4:42 am
by abdullah<cse du>
This is very easy problem. I can say you my method to solve this problem.

1. Find the decimal equavalent for the two binary number.

2.Find the GCD of this two decimal number.

3. If GCD is 1 then print the second condition.

4. Or print the first condition.



I think it will help you.

Re: can someone answer me??

Posted: Thu Sep 06, 2007 12:58 pm
by oliveralderete
"You can assume that all strings in the input will be valid acording to the rules"
then this kind of input does NOT exist in the input!
justforfun wrote:what is the correct output when input are:
1
1
and
0
0

or is there any special input??
i always got WA.... :cry:
salu2,

Re: 10193 - All You Need Is Love

Posted: Thu Oct 15, 2009 6:41 am
by Azad Salam
Getting TLE....
can anyone help me to improve the algo???
how can i get decimal from binary more efficiently????
or get gcd ?????

it is really a simple problem ...so these tle are really disappointing me....

my code:{in C}

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{ long int t,i,s1,s2,p=1,l1,ctr;
char str1[35],str2[35];
scanf("%lld",&t);
getchar();
while(p<=t)
{ gets(str1);
gets(str2);
l1=strlen(str1);
s1=0;
for(i=0,l1-=1;str1;i++,l1--)
{ if(str1=='1')
s1+=pow(2,l1);
}

l1=strlen(str2);
s2=0;
for(i=0,l1-=1;str2;i++,l1--)
{ if(str2=='1')
s2+=pow(2,l1);
}


if(s1<s2)
{ i=s1;
s1=s2;
s2=i;
}
ctr=1;
for(i=2;i<=s2 && ctr;i++)
{ if(s1%i);
else
{ if(s2%i);
else
ctr=0;
}
}
if(ctr)
printf("Pair #%lld: Love is not all you need!\n",p);
else
printf("Pair #%lld: All you need is love!\n",p);

p++;
}
return 0;
}



what should be the output for

1
1

0
0

111
1

111001
0



<THNX in ADVANCE>

Re: 10193 - All You Need Is Love

Posted: Thu Oct 15, 2009 6:56 am
by Jehad Uddin
ur string reading is so bad,

Code: Select all

for(i=0,l1-=1;str1[i];i++,l1--)
{ if(str1[i]=='1')
s1+=pow(2,l1);
chnge it to for(i=0;i<strlen(str1);i++) ...... 
}
use manual power function or just multiply by 2 .... built in pow will make trouble sometimes,
it will make a binary no to decimal for(i=0,k=0;i<strlen(str1);i++) k=k*2+str1-48;
make a gcd function and it will be helpful

Code: Select all

int gcd(int a,int b)
{
 if(b==0) return a;
else return gcd(b,a%b);}
when posting a code in forum use

Code: Select all

  .... [  \code]

Re: 10193 - All You Need Is Love

Posted: Thu Oct 15, 2009 9:36 am
by Azad Salam
GOT AC>>>

MADE A LOOP For gcd....

Thnx for ur help

:D
:D

Why i WA for my efficient code!

Posted: Thu Jan 31, 2013 11:54 am
by robinmbstu12
This is my code for 10193. I found that the gcd of binary is same as Decimal.Is it true?? Like that ,the gcd of 24 &27 is 3.And the binary expression of this two decimal is
11000 & 11011.I also found that gcd of 11000 & 11011 is also 3.So why WA for this following code::

#include<stdio.h>
unsigned int Euclid_g_c_d(unsigned int a, unsigned int b){
if(b==0)
return a;
else
return Euclid_g_c_d(b,a%b);
}
int main(){
unsigned int a,b,gcd,T,t;
scanf("%u",&T);
for( t=1;t<=T;t++){
scanf("%u%u",&a,&b);
if(Euclid_g_c_d(a,b)==1)
printf("Pair #%u: Love is not all you need!\n",t);
else
printf("Pair #%u: All you need is love!\n",t);
}
return 0;
}

plz anyone help me. :D

Re: Why i WA for my efficient code!

Posted: Thu Jan 31, 2013 9:23 pm
by brianfry713
Input:

Code: Select all

2
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111110
Correct output:

Code: Select all

Pair #1: All you need is love!
Pair #2: Love is not all you need!

Re: 10193 - All You Need Is Love

Posted: Fri Mar 07, 2014 1:33 pm
by uDebug
Here's some input / output I found useful during testing / debugging.

Input:

Code: Select all

3
11111111111111
111
111111111111111111111111111111
11
1010
1010
AC Output:

Code: Select all

Pair #1: Love is not all you need!
Pair #2: All you need is love!
Pair #3: All you need is love!

Re: 10193 - All You Need Is Love

Posted: Sat Feb 07, 2015 7:27 am
by xnorax
I got an accepted answer! :D
but how it comes to mind that I have to convert it to decimal!! :-?
description does not mention even one 'decimal' word!