UVA 1589 Xiangqi——模拟

网友投稿 656 2022-11-29

UVA 1589 Xiangqi——模拟

UVA 1589 Xiangqi——模拟

模拟题,我的做法是先让黑将分别上下左右移动,对每一种情况  先判断是否能被马将死(列举8种情况),然后判断是否能被 将 车 炮 将死(以黑将为中心十字展开,判断是否有 将 车 炮)

注意:

1.开局两将正对红方必输;

2.吃子情况;

3.输入问题(因为输入错了好多次)

#include #include #include #include int main(){// freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout); int judgewin(int qipan[15][15], int x, int y); int qipan[15][15]; char s[5]; int n,x,y; while(scanf("%d %d %d", &n, &x, &y) == 3 && n && x && y){ memset(qipan,0,sizeof(qipan));//制盘 int x1, y1; while(n--){ scanf("%s%d%d", s, &x1, &y1); qipan[x1][y1] = s[0]; }//放子 if(judgewin(qipan,x,y)) printf("YES\n"); else printf("NO\n"); }}int judgewin(int qipan[15][15], int x, int y){ int judge(int qipan[15][15], int x, int y); char ch; int i; for(i = x; i <= 10; i++) if(qipan[i][y] != 0) break; if(i <=10 && qipan[i][y] == 'G') return 0; /*上*/ if(x-1 >= 1){ ch = qipan[x-1][y]; qipan[x-1][y] = 0; if(judge(qipan,x-1,y)) return 0; } qipan[x-1][y] = ch; /*下*/ if(x+1 <= 3){ ch = qipan[x+1][y]; qipan[x+1][y] = 0; if(judge(qipan,x+1,y)) return 0; } qipan[x+1][y] = ch; /*左*/ if(y-1 >= 4){ ch = qipan[x][y-1]; qipan[x][y-1] = 0; if(judge(qipan,x,y-1)) return 0; } qipan[x][y-1] = ch; /*右*/ if(y+1 <= 6){ ch = qipan[x][y+1]; qipan[x][y+1] = 0; if(judge(qipan,x,y+1)) return 0; } qipan[x][y+1] = ch; return 1;}int judge(int qipan[15][15], int x, int y){ /*马*/ if(qipan[x+1][y-2] == 'H' && qipan[x+1][y-1] == 0) return 0; if(qipan[x+2][y-1] == 'H' && qipan[x+1][y-1] == 0) return 0; if(qipan[x+1][y+2] == 'H' && qipan[x+1][y+1] == 0) return 0; if(qipan[x+2][y+1] == 'H' && qipan[x+1][y+1] == 0) return 0; if(x-1>=1 && qipan[x-1][y+2] == 'H' && qipan[x-1][y+1] == 0) return 0; if(x-2>=1 && qipan[x-2][y+1] == 'H' && qipan[x-1][y+1] == 0) return 0; if(x-2>=1 && qipan[x-2][y-1] == 'H' && qipan[x-1][y-1] == 0) return 0; if(x-1>=1 && qipan[x-1][y-2] == 'H' && qipan[x-1][y-1] == 0) return 0; /*炮 车 将*/ int i, num = 0; for(i = x; i >= 1; i--){ if(num == 1 && qipan[i][y] != 0){ num++; if(qipan[i][y] == 'C') return 0; } if(qipan[i][y] != 0 && num == 0){ num++; if(qipan[i][y] =='R') return 0; } } num = 0; for(i = x; i <= 10; i++){ if(num == 1 && qipan[i][y] != 0){ num++; if(qipan[i][y] == 'C') return 0; } if(qipan[i][y] != 0 && num == 0){ num++; if(qipan[i][y] == 'G' || qipan[i][y] =='R') return 0; } } num = 0; for(i = y; i >= 1; i--){ if(num == 1 && qipan[x][i] != 0){ num++; if(qipan[x][i] == 'C') return 0; } if(qipan[x][i] != 0 && num == 0){ num++; if(qipan[x][i] =='R') return 0; } } num = 0; for(i = y; i <= 9; i++){ if(num == 1 && qipan[x][i] != 0){ num++; if(qipan[x][i] == 'C') return 0; } if(qipan[x][i] != 0 && num == 0){ num++; if(qipan[x][i] =='R') return 0; } } return 1;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:解决使用@RequestParam注解和泛型遇到的问题
下一篇:UVA 201 Squares——思路题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~