题意:背景就是象棋,
题解:坑点1(wa的第一天):将军可以吃掉相邻的棋子,(然行列也写反了orz)
坑点2(wa的第二天):将军到马要反过来写,边界有误,并且第一次碰到的车才算(写到后来都忘了)
#define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) const int maxn = 1e3 + 10; int a[maxn]; typedef long long ll; int dr = 0; int n, sr, sc; double z; char mmp[11][10]; int dir[4][2] = { 0,1 ,1,0, 0,-1, -1,0 }; bool check(int r, int c) { if (r < 1 || r>3 || c < 4 || c>6)return 1; int nothas = 0; if (mmp[r][c])nothas == 1; //up int nr = r, nc = c; int one = 0,first = 1; while (nr--&&nr>=1) { if (first&&mmp[nr][nc] == 'R')return 1; if (one&&mmp[nr][nc] == 'C')return 1; if (mmp[nr][nc] != 0)if (first == 1)one = 1,first=0; else one = 0; } //down nr = r, nc = c; one = 0; first = 1; while (nr++&&nr <= 10) { if (first&&(mmp[nr][nc] == 'R' || mmp[nr][nc] == 'G'))return 1; if (one&&mmp[nr][nc] == 'C')return 1; if (mmp[nr][nc] != 0)if (first == 1)one = 1, first = 0; else one = 0; } //left nr = r, nc = c; one = 0; first = 1; while (nc++&&nc <= 9) { if (first&&mmp[nr][nc] == 'R')return 1; if (one&&mmp[nr][nc] == 'C')return 1; if (mmp[nr][nc] != 0)if (first == 1)one = 1, first = 0; else one = 0; } //right nr = r, nc = c; one = 0; first = 1; while (nc--&&nc >= 1) { if (first&&mmp[nr][nc] == 'R')return 1; if (one&&mmp[nr][nc] == 'C')return 1; if (mmp[nr][nc] != 0)if (first == 1)one = 1, first = 0; else one = 0; } //horse nr = r, nc = c; if (mmp[nr + 1][nc+1] == 0) {if (mmp[nr + 2][nc + 1] == 'H' || mmp[nr + 1][nc + 2] == 'H')return 1;} if (mmp[nr + 1][nc - 1] == 0) { if (mmp[nr + 2][nc - 1] == 'H' || mmp[nr + 1][nc - 2] == 'H')return 1; } if (nr>=2&&mmp[nr-1][nc+1] == 0) { if (mmp[nr-1][nc + 2] == 'H' || (nr>=3&&mmp[nr-2][nc + 1] == 'H'))return 1; } if (nr >= 2 && mmp[nr - 1][nc - 1] == 0) { if (mmp[nr - 1][nc - 2] == 'H' || (nr >= 3 && mmp[nr - 2][nc - 1] == 'H'))return 1; } return 0; } int main() { while (cin >> n >> sr >> sc && (n || sr || sc)) { mmm(mmp, 0); rep(i, 1, n) { char c; cin >> c; int x, y; cin >> x >> y; mmp[x][y] = c; } int cnt = 0; rep(i, 0, 3) { if (check(sr + dir[i][0], sc + dir[i][1])) cnt++; } if (cnt == 4)puts("YES"); else puts("NO"); } } /* 2 3 5 H 2 5 C 1 5 3 1 5 H 4 5 G 10 5 C 7 5 2 1 5 R 4 4 G 10 5 3 1 5 G 10 4 R 5 5 H 3 7 4 1 5 G 10 4 C 6 5 H 5 5 R 1 1 5 1 5 G 10 4 C 6 5 H 5 5 H 4 5 R 1 1 3 1 5 G 10 4 C 2 7 H 3 7 3 1 5 G 10 4 R 5 5 R 1 6 4 1 5 G 10 4 R 5 5 R 1 6 H 3 7 0 0 0 */
第一天的wa
#include<iostream> #include<string> #include<cstring> #include<cmath> #include<cstdio> #include<cstdlib> #include<stdio.h> #include<algorithm> #include<set> #include<bitset> #include<queue> using namespace std; #define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++) #define per(i,j,k) for(int i = (int)j;i >= (int)k;i --) #define debug(x) cerr<<#x<<" = "<<(x)<<endl #define mmm(a,b) memset(a,b,sizeof(a)) #define pb push_back #define eps 1e-7 typedef long long ll; const int maxn = 1e6 + 4; //const ll mod = 1e9 + 7; int mmp[11][11]; int n = 0; int dir[4][2] = { 0,1 ,1,0, 0,-1, -1,0 }; struct node { int x, y, t; node(int x = 0, int y = 0, int t = 0) :x(x), y(y), t(t) {} void sc() { scanf("%d%d", &x, &y); } }; int vis[11][11]; string op[8]; int r[8], c[8]; int main() { int sr, sc; begin: while (cin >> n>>sr>>sc&&(n||sr||sc)) { mmm(mmp, 0); mmm(vis, 0); rep(i, 1, n) { //string op; int r, c; cin >> op[i] >> r[i] >> c[i]; vis[r[i]][c[i]] = 1; } rep(k, 1, n) { if (op[k] == "R") { int i = r[k]; int ok = 1; while (i--) { if (vis[i][c[k]] )ok = 0; if (ok)mmp[i][c[k]] = 1; } i = r[k]; ok = 1; while (i++&i<=10) { if (vis[i][c[k]] )ok = 0; if (ok)mmp[i][c[k]] = 1; } int j = c[k]; ok = 1; while (j--) { if (vis[r[k]][j] && ok == 1)ok = 0; if (ok)mmp[r[k]][j] = 1; } j = c[k]; ok = 1; while (j++&&j<=10) { if (vis[r[k]][j] && ok == 1)ok = 0; if (ok)mmp[r[k]][j] = 1; } //rep(i, 1, 10)mmp[i][c[k]] = 1; //rep(j, 1, 9)mmp[r[k]][j] = 1; } if (op[k] == "G") { per(i, 9, 1) { if (vis[i][c[k]])break; if (i == sr && sc == c[k]) { puts("NO"); goto begin; } mmp[i][c[k]] = 1; } } if (op[k] == "C") { int i = r[k]; int ok = 0; while (i--) { if (vis[i][c[k]]) if( ok == 1)ok = 0; else ok = 1; if (ok)mmp[i][c[k]] = 1; } i = r[k]; ok = 0; while (i++&&i<=10) { if (vis[i][c[k]]) if (ok == 1)ok = 0; else ok = 1; if (ok)mmp[i][c[k]] = 1; } int j = c[k]; ok = 0; while (j--) { if (vis[r[k]][j])if(ok == 1)ok = 0; else ok = 1; if (ok)mmp[r[k]][j] = 1; } while (j++) { if (vis[r[k]][j]) if( ok == 1)ok = 0; else ok = 1; if (ok)mmp[r[k]][j] = 1; } } if (op[k] == "H") { if (c[k] + 2 <= 10)if (!vis[r[k]][c[k] + 1])mmp[r[k] + 1][c[k] + 2] = mmp[r[k] - 1][c[k] + 2] = 1; if (c[k] - 2 <= 10)if (!vis[r[k]][c[k] - 1])mmp[r[k] + 1][c[k] - 2] = mmp[r[k] - 1][c[k] - 2] = 1; if (r[k] - 2 <= 9)if (!vis[r[k]-1][c[k]])mmp[r[k] - 2][c[k] - 1] = mmp[r[k] - 2][c[k] +1] = 1; if (r[k] + 2 <= 9)if (!vis[r[k] + 1][c[k]])mmp[r[k] + 2][c[k] - 1] = mmp[r[k] + 2][c[k] + 1] = 1; } } int ok=0; rep(i, 0, 3) { int dr = sr + dir[i][0]; int dc = sc + dir[i][1]; if (dr > 3 || dr < 1 || dc>6 || dc < 4)continue; if (mmp[dr][dc] == 0)ok = 1; } rep(i, 1, 10) {rep(j, 1, 9)cout << mmp[i][j] << ' ';cout << endl;} if (ok)puts("NO"); else puts("YES"); } } /* 2 2 5 H 2 3 R 2 4 */