Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Wednesday, January 29, 2014

NFURY - Training Land of Fury

Training Land of Fury

here the solution for NFURY spoj or training land of fury spoj .

#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
 int *list=(int*)calloc(1001,sizeof (int));
 list[1]=1;
 list[2]=2;
 list[3]=3;
 int i,max,j;
 for (i=4; i<=1000; i++)
 {
  max=1000000;
  if ((int)sqrt(i)==sqrt(i))
  {
   list[i]=1;
  }
  else
  {
   for (j=1; j<=i/2; j++)
   {
    if (list[j]+list[i-j] < max)
     max=list[j]+list[i-j];
   }
   list[i]=max;
  }
 }

 int t,n;
 cin>>t;
 while(t--)
 {
  cin>>n;
  cout<<list[n]<<endl;
 }
 return 0;

}

2 comments:

Your comment is valuable to us