Skip to content

Instantly share code, notes, and snippets.

@kuoe0
Created November 4, 2012 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuoe0/4012113 to your computer and use it in GitHub Desktop.
Save kuoe0/4012113 to your computer and use it in GitHub Desktop.
/*=============================================================================
# FileName: 2766_Laserbox.cpp
# Desc: POJ 2766 - http://poj.org/problem?id=2766
# Author: KuoE0
# Email: kuoe0.tw@gmail.com
# HomePage: http://kuoe0.ch/
# Version: 0.0.1
# LastChange: 2012-11-04 21:35:23
# History:
=============================================================================*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
int step[ 4 ][ 2 ] = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } };
int main() {
int t;
scanf( "%d", &t );
while ( t-- ) {
int r, c, n, m, dir;
scanf( "%d %d", &n, &m );
vector< vector< bool > > graph = vector< vector< bool > >( n + 2, vector< bool >( n + 2, 0 ) );
for ( int i = 0; i < m; ++i ) {
scanf( "%d %d", &r, &c );
graph[ r ][ c ] = 1;
}
scanf( "%d %d", &r, &c );
dir = !r ? 0 : ( r == n + 1 ? 2 : ( !c ? 3 : 1 ) );
do {
r += step[ dir ][ 0 ], c += step[ dir ][ 1 ];
dir = graph[ r ][ c ] ? ( dir + 1 ) % 4 : dir;
} while ( r && r != n + 1 && c && c != n + 1 );
printf( "%d %d\n", r, c );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment