hdu 4121 Xiangqi
2013-10-08 23:15
288 查看
我写的时候主要有2个大错误
1:判断2点之间多少个子,没有保证起点<终点
2:马的方向是8个,我画图时搞了4个。。。
1:判断2点之间多少个子,没有保证起点<终点
2:马的方向是8个,我画图时搞了4个。。。
#include <iostream> #include <vector> #include <stack> #include <cstring> #include <cstdlib> #include <cstdio> #include <algorithm> using namespace std; /* define */ #define sf(a) scanf("%d",&a) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define clr(a) memset(a,0,sizeof(a)) /* define */ int dx[4]={0,0,1,-1}; int dy[4]={-1,1,0,0}; bool flag[50][50]; const int inf = (1<<29); int n,newx,newy; struct chess{ int x,y; char kind[10]; }p[20]; int row(chess t){ int st=min(newy,t.y),ed=max(newy,t.y),pos=t.x; int ans=0; for(int i=st+1;i<ed;i++) if(flag[pos][i]) ans++; return ans; } int col(chess t){ int st=min(newx,t.x),ed=max(newx,t.x),pos=t.y; int ans=0; for(int i=st+1;i<ed;i++) if(flag[i][pos]) ans++; return ans; } /* if hob horse return true */ bool hobHorse(chess t){ int x=t.x,y=t.y; if(y>newy && x>newx){ if(flag[x][y-1]) return true; if(flag[x-1][y]) return true; return false; } else if(y>newy && x<newx){ if(flag[x][y-1]) return true; if(flag[x+1][y]) return true; return false; } else if(y<newy && x>newx){ if(flag[x][y+1]) return true; if(flag[x-1][y]) return true; return false; } else if(y<newy && x<newx){ if(flag[x][y+1]) return true; if(flag[x+1][y]) return true; return false; } return false; } bool ok(int x,int y){ for(int i=1;i<=n;i++){ int _x=p[i].x,_y=p[i].y; if(flag[_x][_y]==0) continue; if(p[i].kind[0]=='G'){ if(y==_y && col(p[i])==0) return true; } else if(p[i].kind[0]=='R'){ if(x==_x && row(p[i])==0) return true; if(y==_y && col(p[i])==0) return true; } else if(p[i].kind[0]=='H'){ if(abs(y-_y)==2 && abs(x-_x)==1){ if(!hobHorse(p[i])) return true; } if(abs(y-_y)==1 && abs(x-_x)==2){ if(!hobHorse(p[i])) return true; } } else if(p[i].kind[0]=='C'){ if(x==_x && row(p[i])==1) return true; if(y==_y && col(p[i])==1) return true; } } return false; } int main(){ int x,y; while(~scanf("%d%d%d",&n,&x,&y)&&(n+x+y)){ bool dead=true; clr(flag); rep(i,1,n){ scanf("%s",p[i].kind); scanf("%d%d",&p[i].x,&p[i].y); flag[p[i].x][p[i].y]=1; } for(int i=0;i<4;i++){ newx=x+dx[i]; newy=y+dy[i]; if(newx<1 || newx>3 ||newy<4 ||newy>6) continue; if(flag[newx][newy]){ flag[newx][newy]=0; if(!ok(newx,newy)){ dead=false; goto A; } flag[newx][newy]=1; } else { if(!ok(newx,newy)){ dead=false; goto A; } } } A:; if(dead) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- HDU 4121 Xiangqi 模拟
- hdu 4121 xiangqi 模拟
- hdu 4121 Xiangqi(模拟)
- 2011 ACM 福州赛区现场赛第一题 (A .Xiangqi)HDU 4121 Xiangqi by kuangbin
- HDU 4121 Xiangqi
- HDU 4121 Xiangqi
- HDU 4121 Xiangqi 模拟
- HDU 4121 Xiangqi --模拟
- HDU 4121 Xiangqi 我老了?
- HDU 4121 Xiangqi 模拟题
- HDU 4121 Xiangqi
- hdu 4121 Xiangqi 大模拟
- Poj 4001 Hdu 4121 Xiangqi
- HDU 4121 Xiangqi
- HDU-4121 Xiangqi 模拟
- HDU 4121 Xiangqi (算是模拟吧)
- HDU 4121 Xiangqi --模拟
- hdu 4121 Xiangqi
- HDU 4121 Xiangqi(模拟+恶心)
- HDU 4121 Xiangqi 模拟题