Wikipedia

Search results

Wednesday 10 December 2014

SPOJ 19291. Structures (WPC5A)

http://www.spoj.com/problems/WPC5A/

we know if  'x' is odd and  x^2+y^2=z^2  then  x^2=(y+z)(y-z)  so  (y-z) must be the smallest factors of x^2.
Therefore this problem is all about  finding the number of  factors of  size of  a side and then printing the value of  count_factor(n)/2.........simple problem just do it..

SPOJ 18240. GENIE SEQUENCE (KURUK14)

/http://www.spoj.com/problems/KURUK14/

simple DP it is...........C++ code goes  here:




#include <bits/stdc++.h>
using namespace std;
int main()
{
 int t;     
cin>>t;   
 while(t--)    
 {
  int n,i,flag=0,x;
  cin>>n;    
 int a[1001]={0};
  for(i=0;i<n;i++)
  {
  cin>>x;    
  if(a[x+1]==0) 
  {
   a[x+1]=1;    
   flag++;     
  }
  else if(a[n-x]==0)                
  {
   a[n-x]=1;      
   flag++;        
  }
  }
  if(flag==n)                
  {
  printf("YES\n");
  }
  else                
  {
  printf("NO\n");
  }
 }
 return 0;
}

Sunday 7 December 2014

Spoj problem : 6297. Decipher ROOTCIPH

Link of the Question
http://www.spoj.com/problems/ROOTCIPH/

Purely mathematical question.........based on our algebraic knowledge.
Here
      In question given that roots of the cubical polynomial  x3 + ax2 + bx + c are the coordinates of the aircraft  relative to the radar.
                             and we have to find  the square of the distance to the enemy aircraft.so simply go for the solution as......square of the distance=(a*a-2*b);
                      Apply this in the test case given you'll find the output correctly !!
One more thing use scanf and printf instead of  cin cout.