UVa : 11760


//============================================================================
// Name        : UVa_11760.cpp
// Author      : Shahab
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#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;

		if ( r - 1 >= 0 && !(row [r - 1] || col [c]) ) // up
			canEscape = true;
		else if ( r + 1 < R && !(row [r + 1] || col [c]) ) // down
			canEscape = true;
		else if ( c - 1 >= 0 && !(row [r] || col [c - 1]) )
			canEscape = true;
		else if ( c + 1 < C && !(row [r] || col [c + 1]) )
			canEscape = true;
		else if ( !(row [r] || col [c]) )
			canEscape = true;

		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;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s