this is my code…i am continuously getting wrong answer …please help me out
#include
int main()
{
unsigned long A;
int N,K,i,j;
scanf("%d%d%d",&A,&N,&K);
int x[100];
for(i=0;i
x[i]=0;
for(i=0;i<A;i++)
{ for(j=0;j
{
if(x[j]
{ x[j]++;
break;
}
else
{x[j]=0;
}
}
}
for(i=0;i
printf("%d",x[i]);
printf("\n");
return 0;
}
Firstly, the input format is k then n then finally a.
Next, you need to understand the basic idea behind solving the problem. All that’s inside is, every time the count of particles in any cell becomes greater than n, the number of particles in that cell becomes 0 and one particle is carried over to next cell.
Lets take an example of k = 4 , n = 1 , a = 3.
Now,
1: 0 0 0 //initially
2: 1 0 0
3: 0 1 0
4: 1 1 0
5: 0 0 1
Observing this one can see that for each cell, final number of particles become:
(number of particles bombarded on it) mod n
and the number of particles carried to next cell is
(number of particles bombarded on it) /(integer division) n
and for each cell the number of particles carried to it by the last cell becomes the number of particles bombarded on it.