Fuzhou 2011 Xiangqi

原创 2012年03月24日 18:53:03

今天跟人做这个,超级模拟,wa了七次……

#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 模拟

题意:判断一个棋局是否将对方将死,目前已经将军 直接模拟(虽然比较麻烦) #include #include #include using namespace std; int i,j,x,y,m,n...
  • dlutjwh
  • 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-1003 hdu4123 Bob’s Race

同样北大的题,题目很简单,想法很简单也很容易实现,但却要优化好,否则很容易超时。 题目描述:Bob要办一场赛跑比赛,有N个房子互相相连,任意两个房子间有且仅有一天路(树形结构),有N个人分别从这N个...

【模拟】2011 Asia Fuzhou Regional Contest hdu 4121

看清楚题目,帅只能走四个方向,枚举四个方向,然后先判马,再判四个方向的直线(其中若直线最近的是马或炮,判后面那个是否是炮) #include #include #include #includ...
  • leolin_
  • leolin_
  • 2011年12月02日 22:21
  • 492

2011 Fuzhou Online HDU 4068

暴力搜索。 #include #include #include #include #include using namespace std; #define nMax 30 string s[...
  • utoppia
  • 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 又是大陆的一场区赛,难度还是大不少 现...

2011 Asia Fuzhou Regional Contest-1005 hdu4125 Moles

题目描述:     给N个数(标号为1-N)按顺序建一棵二叉排序树,然后按数字从小到大遍历这棵树,每走过一个标号为奇数的节点记录1,偶数记录0,访问完所有节点回到地面上之后便能得到一串0-1序列...

2011 Asia Fuzhou Regional Contest-1002 hdu4122

用RMQ选取指定区间内的最小值 #include #include #include #include #include #include #include #include us...

xiangqi.java

  • 2010年11月15日 13:34
  • 2KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Fuzhou 2011 Xiangqi
举报原因:
原因补充:

(最多只允许输入30个字)