You are given two arrays a and b of length n and m respectively
Consider the following (n + m) points on the coordinate plane:
|(~1,0), (a2,0), (a3,0)...... (an,0)]
|(61,1), (b2,1), (b3, 1)...... (bm, 1)]
Find the area of the largest rectangle that can be constructed from the given points
Answers
Answer:
The smile on my face doesn’t mean my life is perfect, it just means I appreciate what I have and what God has blessed me with...
or if you like this please five me thanks and follow me..
hii my brothers and sisters please help me to complete my 1000 answer please.....
Answer:
Check this out! I hope it helps you.
#include <iostream>
using namespace std;
int main()
{
int a[100],b[100],length,breadth1,breadth2,l1,k,j,l,i,area,y=0,z=1,t,m,n,max=0,s=1;
cin>>t;
while(s<=t)
{
cin>>m>>n;
for(i=0;i<m;i++)
{
cin>>a[i];
}
for(j=0;j<n;j++)
{
cin>>b[j];
}
for(i=0;i<m;i++)
{
cout<<a[i];
}
cout<<endl;
for(j=0;j<n;j++)
{
cout<<b[j];
}
cout<<endl;
for(i=0,j=0;i<m,j<n;i++,j++)
{
for(k=i+1,l=j+1;k<m,l<n;k++,l++)
{
breadth1=a[k]-a[i];
breadth2=b[l]-b[j];
if(breadth1==breadth2)
{
length=z-y;
area=length*breadth1;
if(area>max)
{
max=area;
}
break;
}
}
}
cout<<max;
t++;
}
}
Explanation:
Condition for being a rectangle is that the breadth of opposite sides is equal and the length of the opposite sides is equal.
So here the condition is 'a' is array representing (a1,0),(a2,0) and so on...
Taking y=0
and 'b' is another array representing (b1,1),(b2,1)....
taking z=1
so length will always be the difference of 1.
Hence, we only need to compare the rectangle's breadth
so take two variables, compare their breadth by traversing array and find area.