Pages

Wednesday, June 1, 2011

UVA Problem#11760

Question:

Solution:

1. Take 2 Boolean array (e.g bool row[10000 + 5]; bool col[10000 + 5]; )
2. Let all the elements of the above two array be false. The easiest way to do this is by using memset(...,...,)
3. Then start taking the inputs as "r" and "c"and turn the row[r] and col[c] into true from false.
4. Then check the 4 places of Arif where he can move. 
5. Print your result.
Pseudo code is given below:


#include <iostream>
#include <cstring>
using namespace std;

int main() {
    int R;
    int C;
    int N;
    int cases = 0;

    bool row [10000 + 5];
    bool col [10000 + 5];

    while ( scanf ("%d %d %d", &R, &C, &N) ) {

        if ( R == 0 && C == 0 && N == 0 )
            break;

        memset (row, false, 10005);
        memset (col, false, 10005);

        int r;
        int c;
        for ( int i = 0; i < N; i++ ) {
            scanf ("%d %d", &r, &c);
            row [r] = col [c] = true;
        }

        scanf ("%d %d", &r, &c);

        bool canEscape = false;
............
............
{check the four places}
..........
.........
......... 
  if ( canEscape )
            printf ("Case %d: Escaped again! More 2D grid problems!\n", ++cases);
        else
            printf ("Case %d: Party time! Let's find a restaurant!\n", ++cases);
    }

    return 0;
}

No comments:

Post a Comment