UVA - 1589 Xiangqi
生活随笔
收集整理的這篇文章主要介紹了
UVA - 1589 Xiangqi
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Xiangqi
?UVA - 1589?
題目傳送門
解決方法:判斷黑棋是否能有可以下的地方
AC代碼:
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; char mapp[15][15]; void Init() {rep(i,1,10) {rep(j,1,10) {mapp[i][j]='#';}} } int dx[8]={1,2,2,1,-1,-2,-2,-1}; int dy[8]={2,1,-1,-2,-2,-1,1,2}; int bx[8]={1,1,1,1,-1,-1,-1,-1}; int by[8]={1,1,-1,-1,-1,-1,1,1}; int gx[4]={0,1,0,-1}; int gy[4]={1,0,-1,0}; bool judge(int x,int y) {if(x<1||x>3||y<4||y>6) return false;bool juZ=false;int napey1=0,napey2=0,napex1=0,napex2=0;bool juC=false;for(int i=y-1;i>=1;i--) {if(juZ==false&&mapp[x][i]=='R') return false; if(mapp[x][i]!='#'&&mapp[x][i]!='R'){juZ=true;napey1=i;break;}} //是否有車for(int i=napey1-1;i>=1;i--) {if(juZ==true&&juC==false&&mapp[x][i]=='C') return false; if(mapp[x][i]!='#'&&mapp[x][i]!='C')break;} //是否有炮juZ=false;juC=false;for(int i=y+1;i<=9;i++) {if(juZ==false&&mapp[x][i]=='R') return false; if(mapp[x][i]!='#'&&mapp[x][i]!='R'){juZ=true;napey2=i;break;}}//是否有車for(int i=napey2+1;i<=9;i++) {if(juZ==true&&juC==false&&mapp[x][i]=='C') return false; if(mapp[x][i]!='#'&&mapp[x][i]!='C')break;}//是否有炮juZ=false;juC=false;for(int j=x-1;j>=1;j--) {if(juZ==false&&mapp[j][y]=='R') return false; if(mapp[j][y]!='#'&&mapp[j][y]!='R'){juZ=true;napex1=j;break;}}//是否有車for(int j=napex1-1;j>=1;j--) {if(juZ==true&&juC==false&&mapp[j][y]=='C') return false; if(mapp[j][y]!='#'&&mapp[j][y]!='C')break;}//是否有炮juZ=false;juC=false;for(int j=x+1;j<=10;j++) {if(juZ==false&&mapp[j][y]=='R') return false; if(juZ==false&&mapp[j][y]=='G') return false;if(mapp[j][y]!='#'&&mapp[j][y]!='R'){juZ=true;napex2=j;break;}}//是否有車或紅將for(int j=napex2+1;j<=10;j++) {if(juZ==true&&juC==false&&mapp[j][y]=='C') return false; if(mapp[j][y]!='#'&&mapp[j][y]!='C')break;}//是否有炮juZ=false;juC=false;int tx,ty,bbx,bby;for(int k=0;k<8;k++) { //是否有馬tx=x+dx[k];ty=y+dy[k];bbx=x+bx[k];bby=y+by[k];if(mapp[tx][ty]=='H'&&mapp[bbx][bby]=='#') return false;}return true; } int main() {#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);//ios::sync_with_stdio(0),cin.tie(0);int n,sx,sy;while(scanf("%d %d %d",&n,&sx,&sy)!=EOF&&n+sx+sy) {char qi[10];Init();rep(i,1,n) {int qix,qiy;scanf("%s %d %d",qi,&qix,&qiy);mapp[qix][qiy]=qi[0];}/*rep(i,1,10) {rep(j,1,9) {printf("%c ",mapp[i][j]);}printf("\n");}*/bool ju=false;rep(k,0,3) {int x=sx+gx[k];int y=sy+gy[k];//printf("%d %d\n",x,y);if(judge(x,y)) ju=true;}if(ju) printf("NO\n");else printf("YES\n");}return 0; }?
總結
以上是生活随笔為你收集整理的UVA - 1589 Xiangqi的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: boost序列化(Serializati
- 下一篇: 小节