# Fuzhou 2011 Xiangqi

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int ch_x[4] = {-1, 0, 1, 0};
const int ch_y[4] = {0, 1, 0, -1};
const int ho_x[8] = {-2, -2, -1, 1, 2, 2, 1, -1};
const int ho_y[8] = {-1, 1, 2, 2, 1, -1, -2, -2};
int board[20][20];      //1: red, 2: black
int blackGeneral_x, blackGeneral_y;
int total_red, red_x[10], red_y[10];
char kind[10];

int JudgeLine(int i, int x, int y)
{   //Count how many pieces there are between (red_x[i], red_y[i]) and (x, y)
int res = 0;
if(red_x[i] == x) {
if(red_y[i] < y) {
for(int j = red_y[i] + 1; j != y; j++) {
if(board[x][j] != 0)
res++;
}
}
else {
for(int j = red_y[i] - 1; j != y; j--) {
if(board[x][j] != 0)
res++;
}
}
return res;
}
else if(red_y[i] == y) {
if(red_x[i] < x) {
for(int j = red_x[i] + 1; j != x; j++) {
if(board[j][y] != 0)
res++;
}
}
else {
for(int j = red_x[i] - 1; j != x; j--) {
if(board[j][y] != 0)
res++;
}
}
return res;
}
return -1;
}

bool JudgeChariot(int i, int x, int y)
{   //chariot can eat black general
if(JudgeLine(i, x, y) == 0)
return true;
return false;
}

bool JudgeHorse(int i, int x, int y)
{   //whether horse can eat black general
for(int j = 0; j < 8; j++) {
int tmpx = red_x[i] + ho_x[j];
int tmpy = red_y[i] + ho_y[j];
int footx = red_x[i] + ch_x[j / 2];
int footy = red_y[i] + ch_y[j / 2];
if(tmpx < 1 || tmpx > 10 || tmpy < 1 || tmpy > 9)
continue;
if(footx < 1 || footx > 10 || footy < 1 || footy > 9)
continue;
if(board[footx][footy] != 0)
continue;
if(tmpx == x && tmpy == y)
return true;
}
return false;
}

bool JudgeCannon(int i, int x, int y)
{   //whether connon can eat black general
if(JudgeLine(i, x, y) == 1)
return true;
return false;
}

int main()
{
//freopen("data.in", "rb", stdin);
while(scanf("%d%d%d", &total_red, &blackGeneral_x, &blackGeneral_y) != EOF) {
if(!total_red && !blackGeneral_x && !blackGeneral_y)
break;
memset(board, 0, sizeof(board));
for(int i = 0; i < total_red; i++) {
char tmp;
cin >> tmp >> red_x[i] >> red_y[i];
kind[i] = tmp;
board[red_x[i]][red_y[i]] = 1;
}

bool isCheckmate = true;
for(int i = 0; i < 4; i++) {
int x = blackGeneral_x + ch_x[i];
int y = blackGeneral_y + ch_y[i];
if(!((x >= 1 && x <= 3 && y >= 4 && y <= 6) || (x >= 8 && x <= 10 && y >= 4 && y <= 6)))
continue;
int tmp = board[x][y];
board[x][y] = 2;        //black general moves to this coodinate
bool win = false;
for(int j = 0; j < total_red; j++) {
if(board[red_x[j]][red_y[j]] != 1)  //whether the piece of red has been eaten by black general
continue;
switch(kind[j]) {
case 'G': win = JudgeChariot(j, x, y);  //red general can attack black general in the same way as chariot
break;
case 'R': win = JudgeChariot(j, x, y);
break;
case 'H': win = JudgeHorse(j, x, y);
break;
case 'C': win = JudgeCannon(j, x, y);
break;
}
if(win)
break;
}
if(!win) {
isCheckmate = false;
break;
}
board[x][y] = tmp;
}

if(isCheckmate)
printf("YES\n");
else
printf("NO\n");
}

return 0;
}

• 本文已收录于以下专栏：

## poj4001 uva1589 fuzhou2011 xiangqi 模拟

• dlutjwh
• 2016年11月18日 12:08
• 179

## 2011 Asia Fuzhou Regional Contest-1001 hdu4121 Xiangqi

http://acm.hdu.edu.cn/showproblem.php?pid=4121 模拟 #include #include #include #include #inclu...

## 象棋 (Xiangqi, ACM/ICPC Fuzhou 2011, UVa1589)

DescriptionXiangqi is one of the most popular two-player board games in China. The game represents a...

## 【模拟】2011 Asia Fuzhou Regional Contest hdu 4121

• leolin_
• 2011年12月02日 22:21
• 492

## 2011 Fuzhou Online HDU 4068

• utoppia
• 2013年08月25日 14:40
• 476

## FFF Warm Up Contest 6 - Fuzhou 2011 [iSea]

Board: http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=6832#rank 又是大陆的一场区赛，难度还是大不少 现...

## xiangqi.java

• 2010年11月15日 13:34
• 2KB
• 下载

举报原因： 您举报文章：Fuzhou 2011 Xiangqi 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)