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;
}