开始碰到这个题时觉得太麻烦了直接跳过没做,现在放假了再次看这个题发现没有想象中那么麻烦,主要是题目理解要透彻,基本思路就是用结构体数组存下红方棋子,让黑将军每次移动一下,看移动后是否有一个红方棋子可以吃掉它,这样做黑将军吃子这一情况就可以完美的跳过了,因为只看不在黑将军移动后位置的棋子是否能吃掉他。二维数组模拟棋盘,注意皇宫,玩过象棋的应该对规则比较熟悉,注意憋马脚的情况,不懂得可以看看中国象棋的规则。下面附上我的AC代码,主要是输入那块很烦,只是用getchar()读掉一个回车的话本地测试是对的,交上去却会出现问题,只好用字符串读,然后取首字母。

AC代码:

 #include <stdio.h>
#include <stdlib.h>
#include <string.h> struct qi{
char name;
int x, y;
}hei, qizi[];
int qipan[][], n;
int judge();
int deal(int a, int b);
int H(int, int, int, int);
int C(int, int, int, int);
int R(int, int, int, int);
int main()
{
char s[];
while(scanf("%d %d %d", &n, &hei.x, &hei.y) == && n && hei.x && hei.y)
{
memset(qipan,,sizeof(qipan));
int i;
for(i = ; i < n; i++)
{
scanf("%s %d %d", s, &qizi[i].x, &qizi[i].y);
qizi[i].name = s[];
qipan[qizi[i].x][qizi[i].y] = qizi[i].name;
}
printf("%s\n", judge() ? "YES" : "NO");
}
return ;
} int judge()
{
int i;
for(i = hei.x; i <= ; i++)
{
if(qipan[i][hei.y] != )
{
if(qipan[i][hei.y] == 'G') return ;
else break;
}
}
if(hei.x > && deal(hei.x - , hei.y)) return ;
else if(hei.x < && deal(hei.x + , hei.y)) return ;
else if(hei.y > && deal(hei.x, hei.y - )) return ;
else if(hei.y < && deal(hei.x, hei.y + )) return ;
return ;
} int deal(int a, int b)
{
int i;
for(i = ; i < n; i++)
{
if(qizi[i].x == a && qizi[i].y == b)
continue;
if(qizi[i].name == 'R' || qizi[i].name == 'G')
{
if(R(qizi[i].x, qizi[i].y, a, b))
return ;
}
else if(qizi[i].name == 'C')
{
if(C(qizi[i].x, qizi[i].y, a, b))
return ;
}
else if(qizi[i].name == 'H')
{
if(H(qizi[i].x, qizi[i].y, a, b))
return ;
}
}
return ;
} int H(int x, int y, int a, int b)
{
if(qipan[x + ][y] == && x + == a && (y - == b || y + == b))
return ;
if(qipan[x - ][y] == && x - == a && (y - == b || y + == b))
return ;
if(qipan[x][y + ] == && y + == b && (x - == a || x + == a))
return ;
if(qipan[x][y - ] == && y - == b && (x - == a || x + == a))
return ;
return ;
} int C(int x, int y, int a, int b)
{
int i;
if(x == a)
{
int min = y > b ? b : y;
int max = y > b ? y : b;
int num = ;
for(i = min + ; i < max; i++)
if(qipan[x][i])
num++;
if(num == )
return ;
return ;
}
if(y == b)
{
int min = x > a ? a : x;
int max = x > a ? x : a;
int num = ;
for(i = min + ; i < max; i++)
if(qipan[i][y])
num++;
if(num == )
return ;
return ;
}
return ;
} int R(int x, int y, int a, int b)
{
int i;
if(x == a)
{
int min = y > b ? b : y;
int max = y > b ? y : b;
for(i = min + ; i < max; i++)
if(qipan[x][i] != )
return ;
return ;
}
if(y == b)
{
int min = x > a ? a : x;
int max = x > a ? x : a;
for(i = min + ; i < max; i++)
if(qipan[i][y] != )
return ;
return ;
}
return ;
}

UVA1589——xiangqi的更多相关文章

  1. UVA1589 Xiangqi

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

  2. [刷题]算法竞赛入门经典(第2版) 4-1/UVa1589 - Xiangqi

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1589 #include<iostream> #incl ...

  3. 【习题4-1 Uva1589】Xiangqi

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 车是可以被吃掉的... 注意这个情况. 其他的模拟即可. [代码] #include <bits/stdc++.h> u ...

  4. HDU 4121 Xiangqi 我老了?

    Xiangqi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  6. Uva - 1589 - Xiangqi

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

  7. [算法竞赛入门经典] 象棋 ACM/ICPC Fuzhou 2011, UVa1589 较详细注释

    Description: Xiangqi is one of the most popular two-player board games in China. The game represents ...

  8. Xiangqi(简单模拟)

    4746: Xiangqi 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 总提交: 15            测试通过:2 描述 Xiangqi i ...

  9. TZOJ 4746 Xiangqi(模拟棋盘数组)

    描述 Xiangqi is one of the most popular two-player board games in China. The game represents a battle ...

随机推荐

  1. E. Selling Souvenirs 不会做

    http://codeforces.com/contest/808/problem/E 不理解为什么dp = {cost, cnt1, cnt2}可以 而dp = {cost, cnt1, cnt2, ...

  2. D. Blocks 数学题

    Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent bo ...

  3. sqlserver跟据当天年月日日期查询数据库当天数据

    select * from Client where  CONVERT(varchar(100), Cli_Datetime, 23) ='2017-11-06' 在查询之前要对表中datetime类 ...

  4. JAVA变量介绍

    1.变量: 变量是内存中存储数据的小盒子(小容器),用来存数据和取数据: 2.计算机存储设备的最小信息单元叫位(bit   b); 计算机最小的存储单元叫字节(byte B);   存储单位有(bit ...

  5. 轻量级的绘制图表js库--Morris.js

    Morris.js 是一个轻量级的 JS 库,使用 jQuery 和 Raphaël 来生成各种时序图. 虽说现在移动手机网络已经到了4G,但是在移动web客户端开发过中,为了达到良好的体验效果,需要 ...

  6. where whereis locate find 的用法

    1.where :where ifconfig.用来搜索命令,显示命令是否存在以及路径在哪 2.whereis:whereis vim .用来搜索程序名,而且只搜索二进制文件(参数-b).man说明文 ...

  7. Android 自定义Android ORM 框架greenDAO数据库文件的路径

    import android.content.Context; import android.content.ContextWrapper; import android.database.Datab ...

  8. GitHub 开启 Two-factor authentication,如何在命令行下更新和上传代码

    最近在使用GitHub管理代码,在git命令行管理代码时候遇到一些问题. 如果开起了二次验证(Two-factor authentication两个要素认证),命令行会一直提示输入用户名和密码.查找了 ...

  9. 深入理解Java流机制(一)

    一.前言 C语言本身没有输入输出语句,而是调用"stdio.h"库中的输入输出函数来实现.同样,C++语言本身也没有输入输出,不过有别于C语言,C++有一个面向对象的I/O流类库& ...

  10. python2含有中文路径报错解决办法[\xe4\xbf\xa1\xe6\x81\xaf]

    如图所示 百度的解决办法大多数是针对python3版本的,在脚本开头加# -*- coding:utf-8 -*-,但是python2版本加了编码格式,还是报错,具体解决办法是:path =unico ...