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

Thursday, March 20, 2014

QN01-XOR Game

XOR Game

below given code is for qn01 spoj or xor game spoj.
and code was given ANANT
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
 int n,start,end,tempstart,tempend;
 scanf("%d",&n);
 int array[n];
 for (int i=0; i<n; i++)
  scanf("%d",&array[i]);
 int max=-1,temp;
 for (int i=0; i<n; i++)
 {
  temp=array[i];
  tempstart=i;
  if (max<temp)
  {
   max=temp;
   start=tempstart;
   end=i;
  }
   
  for (int j=i+1; j<n; j++)
  {
   temp=temp^array[j];
   if (max<temp)
   {
    max=temp;
    start=tempstart;
    end=j;
   }
  }
 }
 printf("%d\n%d %d\n",max,start+1,end+1);
 return 0;
}

No comments:

Post a Comment

Your comment is valuable to us