⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2290.cpp

📁 哈尔滨工业大学ACM 竞赛网上在线试题集锦的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 2290 on 2006-07-25 at 21:53:45 */ 
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 64;
const int DIR[][2] = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } };

inline bool legal(int x, int y, int n) { return x >= 0 && x < n && y >= 0 && y < n; }

int main()
{
	int n, t, T, i;
	bool grid[N][N], vst[N][N][4];
	
	scanf("%d", &T);
	for(t = 0; t < T; t++) {
		int r; scanf("%d %d", &n, &r);
		memset(grid, false, sizeof(grid)); memset(vst, false, sizeof(vst));
		for(i = 0; i < r; i++) {
			int a, b; scanf("%d %d", &a, &b);
			grid[a-1][b-1] = true;
		}
		int x, y, d; scanf("%d %d", &x, &y); x--; y--;
		bool cir = false;
		if(x == -1) d = 0;
		else if(y == n) d = 1;
		else if(x == n) d = 2;
		else d = 3;
		while(!cir) {
			x += DIR[d][0]; y += DIR[d][1];
			if(grid[x][y]) d = (d+1)&3;
			if(!legal(x, y, n)) break;
			else if(vst[x][y][d]) cir = true;
			else vst[x][y][d] = true;
		}
		if(!cir) printf("%d %d\n", x+1, y+1);
		else printf("0 0\n");
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -