575 - Skew Binary

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

Moderator: Board moderators

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: Skew Binary: got WA

Post by sazzadcsedu »

First things to note:

why you are creating a new thread while it is already existing?

your code even not pass the sample input.So how do you expect to get Acc!!!.

Code: Select all

for( i = len-1 ; i >= 0 ; i-- )
{
            dec = dec + (input[i]-'0')*(factor-1) ;

            factor = factor * 2 ;
}
Do you think this part is right??For example

Code: Select all

input : 20
your output:2
Actual output: 6
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
dewsworld
New poster
Posts: 12
Joined: Fri Aug 13, 2010 11:52 am

Re: Skew Binary: got WA

Post by dewsworld »

Ooops, I actually didn't find any thread about Skew binary while googling.
And I found my fault. It's pretty silly, I didn't read the question carefully.
Power inits from 2^1 -1 not 2^0 -1 Got AC after that... :)
akshit
New poster
Posts: 1
Joined: Fri Dec 31, 2010 10:33 am

Why i am getting WA for this ?

Post by akshit »

#include<iostream>
using namespace std;
long long int power(long long int n,long long int e)
{
long long int prod,i;
prod=n;
for(i=0;i<e-1;i++)
n=prod*n;
if(e==0)
return 1;
else
return n;
}
int main()
{
long long int m,p,k,q,sum,i,r,j,b[500],a[500];
char c[100];
gets(c);
for(i=0;c!='\0';i++)
{
a=(int)c;
a=(a-48);

}




while(a[0]!=0)
{

q=0;sum=0;
while(i>=0)
{

b[q]=(((power(2,q+1))-1)*a[i-1]);
sum=sum+b[q];
q++;
i--;
}


cout<<sum<<endl;


gets(c);
for(i=0;c!='\0';i++)
{
a=(int)c;
a=(a-48);

}
}



//system("pause");
return 0;
}
sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: Skew Binary: got WA

Post by sazzadcsedu »

Your program even don't pass the sample input.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Post Reply

Return to “Volume 5 (500-599)”