10193 - All You Need Is Love
Moderator: Board moderators
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
-
- New poster
- Posts: 3
- Joined: Wed Aug 29, 2007 4:05 am
- Contact:
Re: can someone answer me??
"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!
then this kind of input does NOT exist in the input!
salu2,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....
(
-
- New poster
- Posts: 7
- Joined: Fri Sep 18, 2009 5:15 pm
- Location: Dhaka
- Contact:
Re: 10193 - All You Need Is Love
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>
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>
-
- Learning poster
- Posts: 74
- Joined: Fri May 08, 2009 5:16 pm
Re: 10193 - All You Need Is Love
ur string reading is so bad,
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
when posting a code in forum use
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++) ......
}
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);}
Code: Select all
.... [ \code]
-
- New poster
- Posts: 7
- Joined: Fri Sep 18, 2009 5:15 pm
- Location: Dhaka
- Contact:
Re: 10193 - All You Need Is Love
GOT AC>>>
MADE A LOOP For gcd....
Thnx for ur help
![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
MADE A LOOP For gcd....
Thnx for ur help
![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
-
- New poster
- Posts: 1
- Joined: Thu Jan 31, 2013 11:30 am
Why i WA for my efficient code!
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](./images/smilies/icon_biggrin.gif)
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](./images/smilies/icon_biggrin.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Why i WA for my efficient code!
Input:Correct output:
Code: Select all
2
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111110
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!
Re: 10193 - All You Need Is Love
Here's some input / output I found useful during testing / debugging.
Input:
AC Output:
Input:
Code: Select all
3
11111111111111
111
111111111111111111111111111111
11
1010
1010
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
I got an accepted answer!
but how it comes to mind that I have to convert it to decimal!!
description does not mention even one 'decimal' word!
![:D](./images/smilies/icon_biggrin.gif)
but how it comes to mind that I have to convert it to decimal!!
![:-?](./images/smilies/icon_confused.gif)
description does not mention even one 'decimal' word!