2018年牛客多校算法寒假训练营练习比赛(第一场)C. 六子冲
题目链接
做法:模拟即可
#include <bits/stdc++.h>
#define P pair<int,int>
#define fir first
#define sec second
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;int n, mp[11][11];
int dx[]={0,-1,1,0,0};
int dy[]={0,0,0,-1,1};
P pos[33];
int inb(int x,int y) {if(x<1||x>4||y<1||y>4) return 0;return 1;
}
int isb(int f, int x) {if(f == 1) return (1 <= x && x <= 6);return (7 <= x && x <= 12);
}
void upb(int x,int y) {int col = isb(1,mp[x][y]);rep(i,1,4) {if( (!inb(x - dx[i], y - dy[i]) || mp[x-dx[i]][y-dy[i]] == -1) &&(!inb(x + 3*dx[i], y + 3*dy[i]) || mp[x+3*dx[i]][y+3*dy[i]] == -1) &&(inb(x+dx[i],y+dy[i]) && isb(col, mp[x+dx[i]][y+dy[i]]))&&(inb(x+2*dx[i],y+2*dy[i]) && isb(col^1, mp[x+2*dx[i]][y+2*dy[i]])) ) {pos[mp[x+2*dx[i]][y+2*dy[i]]]=P(-1,-1), mp[x+2*dx[i]][y+2*dy[i]] = -1;}}rep(i,1,4) {if( (!inb(x - 2*dx[i], y - 2*dy[i]) || mp[x-2*dx[i]][y-2*dy[i]] == -1) &&(!inb(x + 2*dx[i], y + 2*dy[i]) || mp[x+2*dx[i]][y+2*dy[i]] == -1) &&(inb(x-dx[i],y-dy[i]) && isb(col, mp[x-dx[i]][y-dy[i]]))&&(inb(x+dx[i],y+dy[i]) && isb(col^1, mp[x+dx[i]][y+dy[i]])) ) {pos[mp[x+dx[i]][y+dy[i]]]=P(-1,-1), mp[x+dx[i]][y+dy[i]] = -1;}}
}int main() {int CC = 0;while(scanf("%d",&n) != EOF) {memset(mp,-1,sizeof(mp));mp[1][1] = 11; mp[1][2] = 10; mp[1][3] = 9; mp[1][4] = 8;mp[2][1] = 12; mp[2][4] = 7;mp[3][1] = 1; mp[3][4] = 6;mp[4][1] = 2; mp[4][2] = 3; mp[4][3] = 4; mp[4][4] = 5;rep(i,1,4)rep(j,1,4)if(mp[i][j]!=-1)pos[mp[i][j]] = P(i,j);for(int ti = 1 ; ti <= n; ++ti) { int a,b;scanf("%d%d",&a,&b);int x = pos[a].fir, y = pos[a].sec;int tx = x + dx[b], ty = y + dy[b];pos[a] = P(tx,ty); mp[tx][ty] = a; mp[x][y] = -1;upb(tx,ty);}printf("#Case %d:\n", ++CC);rep(i,1,4) { rep(j,1,4) printf("%3d",mp[i][j]<0?0:mp[i][j]); puts(""); }}return 0;
}