10193 - All You Need Is Love

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

Moderator: Board moderators

abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Location: Bangladesh(CSE DU)
Contact:

Post 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.
oliveralderete
New poster
Posts: 3
Joined: Wed Aug 29, 2007 4:05 am
Contact:

Re: can someone answer me??

Post 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,
(
Azad Salam
New poster
Posts: 7
Joined: Fri Sep 18, 2009 5:15 pm
Location: Dhaka
Contact:

Re: 10193 - All You Need Is Love

Post 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>
Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 10193 - All You Need Is Love

Post 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]
Azad Salam
New poster
Posts: 7
Joined: Fri Sep 18, 2009 5:15 pm
Location: Dhaka
Contact:

Re: 10193 - All You Need Is Love

Post by Azad Salam »

GOT AC>>>

MADE A LOOP For gcd....

Thnx for ur help

:D
:D
robinmbstu12
New poster
Posts: 1
Joined: Thu Jan 31, 2013 11:30 am

Why i WA for my efficient code!

Post 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
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why i WA for my efficient code!

Post 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!
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10193 - All You Need Is Love

Post 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!
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
xnorax
New poster
Posts: 9
Joined: Thu Jun 26, 2014 9:31 pm

Re: 10193 - All You Need Is Love

Post 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!
Post Reply

Return to “Volume 101 (10100-10199)”