yKumar
BAN USERthis can be done using dynamic programing
#include<iostream>
using namespace std;
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int main()
{
int a[20],i,n;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
int result[n];
for(i=0;i<n-1;i++)
result[i]=max(a[i],a[i+1]);
result[n-1]=-1;
for(i=n-1;i>=0;i--)
{
if(result[i]==a[i])
if(result[i+1]<result[i])
result[i]=-1;
else
result[i]=result[i+1];
}
for(i=0;i<n;i++)
cout<<a[i]<<"--->"<<result[i]<<"\n";
}
A node of a point quadtree is similar to a node of a binary tree, with the major difference being that it has four pointers (one for each quadrant) instead of two ("left" and "right") as in an ordinary binary tree. Also a key is usually decomposed into two parts, referring to x and y coordinates. Therefore a node contains following information:
4 Pointers: quad[‘NW’], quad[‘NE’], quad[‘SW’], and quad[‘SE’]
point; which in turn contains:
key; usually expressed as x, y coordinates
value; for example a name
simple one,
--> find the largest element in array after the current element
--> now do largest element minus current element.
--> do this for all array elements.
- yKumar April 06, 2013