POJ4001 Xiangqi
来源:互联网 发布:如何处理sql注入 编辑:程序博客网 时间:2024/05/29 13:37
百分百的模拟题,要注意一些细节,如输入用cin(如果用scanf,数据坑爹的话,给你来几个空格就蛋疼了),代码略长,非常考验代码的功底,自己太挫,弹了N次才AC的 TAT
网赛快到了,要加油了!!!
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 100+10;const int xx[4] = {0,0,1,-1};const int yy[4] = {1,-1,0,0};struct node{int x,y,type;node(int x=0,int y=0,int type=0):x(x),y(y),type(type){}};vector<node> xq;int gx,gy;//黑将军初始位置 int mat[maxn][maxn];//记录是否有子 bool in_chess(int x,int y){return x >= 1 && x <= 10 && y >= 1 && y <= 9;}bool in_board(int x,int y){return x>=1 && x <=3 && y >=4 && y <= 6;}bool checkmate(node black,node red){int minx = min(black.x,red.x);int maxx = max(black.x,red.x);int miny = min(black.y,red.y);int maxy = max(black.y,red.y);if(red.type == 1){ if(red.y == black.y){ for(int k = minx+1; k < maxx; k++){ if(mat[k][red.y]) return false; } return true; }else return false;}else if(red.type == 2){ if(black.x == red.x){ for(int k = miny+1; k < maxy; k++) if(mat[red.x][k]) return false; return true; } else if(red.y == black.y){ for(int k = minx+1; k < maxx; k++) if(mat[k][red.y]) return false; return true; }else return false;}else if(red.type == 4){ int cnt = 0; if(red.x == black.x){ for(int k = miny+1; k < maxy; k++) if(mat[red.x][k]) cnt++;if(cnt == 1) return true; else return false; } else if(red.y == black.y){ for(int k = minx+1; k < maxx; k++) if(mat[k][red.y]) cnt++; if(cnt == 1) return true; else return false; }else return false; }else{ for(int i = 0; i < 4; i++){ int tx = red.x+xx[i]; int ty = red.y+yy[i]; if(!in_chess(tx,ty)) continue; if(!mat[tx][ty]){ switch (i){ case 0: if(tx+1==black.x && ty+1 == black.y) return 1; if(tx-1==black.x && ty+1 == black.y) return 1; break; case 1: if(tx+1==black.x && ty-1 == black.y) return 1; if(tx-1==black.x && ty-1 == black.y) return 1; break; case 2: if(tx+1==black.x && ty-1 == black.y) return 1; if(tx+1==black.x && ty+1 == black.y) return 1; break; case 3: if(tx-1==black.x && ty-1 == black.y) return 1; if(tx-1==black.x && ty+1 == black.y) return 1; } } } return false; }}void init(){memset(mat,0,sizeof(mat));xq.clear();}/*1 : 将军 2 : 车 3 :马 4 :炮 */ int main(){int n;while(~scanf("%d%d%d",&n,&gx,&gy) && n|gx|gy){init();while(n--){ char type; int a,b; cin >> type >> a >> b; mat[a][b] = 1; if(type == 'G'){ xq.push_back(node(a,b,1)); } else if(type == 'R'){ xq.push_back(node(a,b,2)); } else if(type == 'H'){ xq.push_back(node(a,b,3)); }else{ xq.push_back(node(a,b,4)); } } bool flag;for(int i = 0; i < 4; i++){ int x = gx + xx[i]; int y = gy + yy[i]; if(in_board(x,y)){flag = 0; node tmp; tmp.x = x; tmp.y = y; for(int j = 0; j < xq.size(); j++){ if(x == xq[j].x && y == xq[j].y) continue; if(checkmate(tmp,xq[j])){ flag = 1; break; } }if(!flag) break; } }if(!flag) cout<<"NO"<<endl;else cout<<"YES"<<endl;}return 0;}
- POJ4001 Xiangqi
- poj4001 Xiangqi
- POJ4001/HDU4121 Xiangqi 大模拟
- BFS、模拟:UVa1589/POJ4001/hdu4121-Xiangqi
- poj4001
- Xiangqi
- poj4001 象棋判断死局
- POJ4001-模拟象棋
- hdu4121 xiangqi
- hdu4121 xiangqi
- Uva1589 - Xiangqi
- hdu4121 Xiangqi
- 1589 - Xiangqi
- 1589 - Xiangqi
- Xiangqi UVA
- 抓牛(poj4001)BFS
- POJ Xiangqi 4001 && HDOJ 4121 Xiangqi
- hdu4121 Xiangqi && uva1589 Xiangqi (模拟)
- Silverlight Telerik RadGridView动态增删行及行列操作
- UITableView中Cell重用机制导致内容重复解决方法
- servlet学习日记
- jstat 详解<转>
- HTTP深入浅出 http请求
- POJ4001 Xiangqi
- WPF之导入导出Excel
- 手机GUI自动化测试介绍
- Android游戏开发之构建游戏框架View与SurFaceView的区别(十)
- ubuntu 纯字符系统下中文乱码问题
- Pro Android学习笔记(二二):用户界面和控制(10):自定义Adapter
- hdu1358 Period (循环节)
- Android软件开发之ListView 详解 (十一)
- 一步一步教你做ios推送