[try Beta version]
Not logged in

 
Bounds Checking

Mar 2, 2011 at 12:55am
I am making a program that tells you how many possible ways there are from the top left to the bottom right. The grid can either be a square/rectangle or an L-shape. The L-grid bounds checking is where I am having problems.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iomanip>
#include <iostream>

using namespace std;

int grid(int low,int left, int right, int bottom)
{
        if(low>bottom)
                return 0;
        if(left>right)
                return 0;
        if(low == 0 || left== 0)
                return 1;
        else
                return grid(low-1,left,right,bottom)+grid(low,left-1,right,bottom);
}



int main()
{
        int startrow,startcol,endrow,endcol,numrow,numcol,topd,rightd,leftd,bottomd;

        startrow=0;
        startcol=0;

        cout<<"Enter the dimentions of your grid starting with the top."<<endl;
        cin>>topd;

        cout<<"Now enter the right dimention(your right must be less then your left)"<<endl;
        cin>>rightd;

        cout<<"Now the left"<<endl;
        cin>>leftd;

        cout<<"Now the bottom(your bottom must be greater then your top)"<<endl;
        cin>>bottomd;
        
        cout<<"You are starting at the top left corner(0,0)"<<endl;
        //cout<<"Enter the ending coordinates(row and colum): "<<endl;

        endrow=bottomd;
        endcol=rightd;

        numrow=endrow-startrow;
        numcol=endcol-startcol;

        if(numrow < 0 || numcol <0)
                cout<<"There are no possible paths "<<endl;
        else
                cout<<"There are "<<grid(numrow,numcol,rightd,bottomd)<<" paths"<<endl;
}


Mar 2, 2011 at 12:57am
Can someone please help?
Mar 2, 2011 at 1:04am
What sort of problems are you having?

-Albatross
Last edited on Mar 2, 2011 at 1:05am
Mar 2, 2011 at 1:14am
no thickness to them..... the grid we are making, are divided up into little squares each having a dimension of 2X2, so it takes four points. So a grid with 4X4 would have a total of 9 squares in it. So our problem is say if we have a top of 4, a left side of 11, a bottom side of 8, and a right side of 6. In the top right corner of the grid, there would be nothing there, so how would we write bounds checking for that area?
Mar 2, 2011 at 1:17am
it is kinda a hard program to explain. did that help?
Mar 2, 2011 at 1:31am
Suppose that you move your L, so the sides of the hole corresponds to the axis x and y.
Then a point is inside the hole if both its coordinates are positive.
Mar 2, 2011 at 1:35am
explain more
Mar 2, 2011 at 5:47pm
move the concave vertex to (0,0). Now your problem was simplified.
Instead of looking for a point inside an L shape, you look for a point in any of the 3 valid rectangles (thing that you know how to do it)

Another one:
An L is formed by the subtraction of two rectangles. If a point is inside the minuend then it is not inside the L.
Topic archived. No new replies allowed.