?? 2232.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 + -