uva1589XIangqi疯狂求助大佬!!!udebug都过,就是WA! 五十分求助!!

请师傅喝茶 2020-01-09 10:14:36
#include<stdio.h>
#include<string.h>
int n, x, y, q, p;
int a[15][15];//标记危险的地方,红自身所在是安全的,除非被其他的红色锁定。
int b[15][15];//标记一下红色的位置,其中1代表将军,2代表战车,3马,4跑
void handle_g(int x, int y);
void handle_r(int x, int y);
void handle_h(int x, int y);
void handle_c(int x, int y);
int main(int argc, char const *argv[])
{
while(scanf("%d %d %d", &n, &x, &y) && n){
q = 0, p = 0;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int judge = 0;
for (int i = 0; i < n; i++){
char c;
int x, y;
getchar();
scanf("%c %d %d", &c, &x, &y);
if (c == 'G')
b[x][y] = 1;
else if (c == 'R')
b[x][y] = 2;
else if (c == 'H')
b[x][y] = 3;
else if (c == 'C')
b[x][y] = 4;
}
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 9; j++){
if (b[i][j] == 1)
{
q = i;
p = j;
}
else if (b[i][j] == 2)
handle_r(i, j);
else if (b[i][j] == 3)
handle_h(i, j);
else if (b[i][j] == 4)
handle_c(i, j);
}
handle_g(q, p);//防止被飞将
if (x - 1 >= 1 && a[x - 1][y] == 0)
judge = 1;
else if (x + 1 <= 3 && a[x + 1][y] == 0)
judge = 1;
else if (y + 1 <= 6 && a[x][y + 1] == 0)
judge = 1;
else if (y - 1 >= 4 && a[x][y - 1] == 0)
judge = 1;
else if (a[x][y] == 2)
judge = 1;
if (judge)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
void handle_g(int x, int y){//考虑一条单项直线就行了 将
for (int i = x - 1; i >= 1; i--){//向下飞将
if (b[i][y] == 0)
a[i][y] = 2;
else{
a[i][y] = 2;
break;
}
}
}
void handle_r(int x, int y){//考虑四周的单项直线 战车
for (int i = y - 1; i >= 1; i--)//向左
{
if (b[x][i] == 0)
a[x][i] = 1;
else{
a[x][i] = 1;
break;
}
}
for (int i = y + 1; i <= 9; i++)//向右
{
if (b[x][i] == 0)
a[x][i] = 1;
else{
a[x][i] = 1;
break;
}
}
for (int i = x - 1; i >= 1; i--)//向上
{
if (b[i][y] == 0)
a[i][y] = 1;
else{
a[i][y] = 1;
break;
}
}
for (int i = x + 1; i <= 10; i++){//向下
if (b[i][y] == 0)
a[i][y] = 1;
else{
a[i][y] = 1;
break;
}
}
}
void handle_h(int x, int y){//马
if (y + 2 <= 9 && b[x][y + 1] == 0){//右边
if (x - 1 >= 1)
a[x - 1][y + 2] = 1;
if (x + 1 <= 10)
a[x + 1][y + 2] = 1;
}
if (y - 2 >= 1 && b[x][y - 1] == 0){//左边
if (x - 1 >= 1)
a[x - 1][y - 2] = 1;
if (x + 1 <= 10)
a[x + 1][y - 2] = 1;
}
if (x - 2 >= 1 && b[x - 1][y] == 0)//上面
{
if (y - 1 >= 1)
a[x - 2][y - 1] = 1;
if (y + 1 <= 9)
a[x - 2][y + 1] = 1;
}
if (x + 2 <= 10 && b[x + 1][y] == 0)//下面
{
if (y - 1 >= 1)
a[x + 2][y - 1] = 1;
if (y + 1 <= 9)
a[x + 2][y + 1] = 1;
}

}
void handle_c(int x, int y){
for (int i = x + 1; i <= 10; i++)//向下
{
if (b[i][y] != 0){
for (int j = i + 1; j <= 10; j++){
a[j][y] = 1;
if (b[j][y] != 0)
break;
}
break;
}
}
for (int i = x - 1; i >= 1; i--)//向上
{
if (b[i][y] != 0){
for (int j = i - 1; j >= 1; j--){
a[j][y] = 1;
if (b[j][y] != 0)
break;
}
break;
}
}
for (int i = y + 1; i <= 9; i++)//向右
{
if (b[x][i] != 0){
for (int j = i + 1; j <= 9; j++){
a[x][j] = 1;
if (b[x][j] != 0)
break;
}
break;
}
}
for (int i = y - 1; i >= 1; i--){//向左
if (b[x][i] != 0){
for (int j = i - 1; j >= 1; j--){
a[x][j] = 1;
if (b[x][j] != 0)
break;
}
}
break;
}
}
...全文
43 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
一星伴月 2020-03-02
  • 打赏
  • 举报
回复
这题是真的变态,就是个模拟,就是条件太多......放弃吧
请师傅喝茶 2020-01-09
  • 打赏
  • 举报
回复
十个小时了,枯了

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧