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

📄 2232.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 2232 on 2006-05-16 at 18:00:16 */ 
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;

const int SN = 1024;
const int QN = 128;
const char PIECE[] = "QKP";
const int Q_DIR[][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { 1, -1 }, { -1, 1 }, { -1, -1 } };
const int K_DIR[][2] = { { 1, 2 }, { 1, -2 }, { -1, 2 }, { -1, -2 }, { 2, 1 }, { 2, -1 }, { -2, 1 }, { -2, -1 }  };

char map[SN][SN];
int w, h;

bool legal(int x, int y) { return x >= 0 && x < h && y >= 0 && y < w && !isupper(map[x][y]); }

int main()
{
	int t, i, j, k, m;
	vector<int> p[3];
	
	for(t = 1; scanf("%d %d", &h, &w) != EOF && h != 0; t++) {
		memset(map, '.', sizeof(map));
		for(i = 0; i < 3; i++) {
			p[i].clear();
			int n; scanf("%d", &n);
			for(j = 0; j < n; j++) {
				int x, y; scanf("%d %d", &x, &y);
				p[i].push_back(x-1); p[i].push_back(y-1);
				map[x-1][y-1] = PIECE[i];
			}
		}
		for(m = 0; m < 2; m++)
			for(i = 0; i < p[m].size()/2; i++) {
				int x = p[m][2*i], y = p[m][2*i+1];
				for(j = 0; j < 8; j++)
					if(m == 0) 
						for(k = 1; k < SN; k++) {
							int cx = x+k*Q_DIR[j][0], cy = y+k*Q_DIR[j][1];
							if(legal(cx, cy) && !isupper(map[cx][cy])) map[cx][cy] = 'x';
							else break;
						}
					else {
						int cx = x+K_DIR[j][0], cy = y+K_DIR[j][1];
						if(legal(cx, cy) && !isupper(map[cx][cy])) map[cx][cy] = 'x';
					}
			}
		int safe = 0;
		for(i = 0; i < h; i++)
			for(j = 0; j < w; j++)
				if(map[i][j] == '.') safe++;
		printf("Board %d has %d safe squares.\n", t, safe);
	}
	
	return 0;
}

⌨️ 快捷键说明

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