CodeForces - 1221B - Knights(思维)

题目链接:https://vjudge.net/problem/CodeForces-1221B

题目大意:

一个n行n列的棋盘,最初,棋盘上的所有格子都是空的,他们必须在每个格子上放置一个白色或黑色的骑士。

骑士是一个特别的棋子,如果满足以下条件之一,则骑士(x1,y1)可以攻击到骑士(x2,y2):

  • |x1-x2| = 2 且 |y1-y2| = 1
  • |x1-x2| = 1 且 |y1-y2| = 2

下面是一些例子。在下面的每张图片中,如果骑士在蓝色格子,则它可以攻击所有红色格子的骑士(并且只能攻击这些格子的骑士)。

决斗的骑士必须是一对不同颜色的骑士,这样这些骑士才能互相攻击。请你找到一种摆盘方案,使决斗次数最多。如果有多个使决斗次数最多的方案,你可以输出任何一种。

可以行列间隔开选一个蓝色棋子,然后让他四个角可以放红色棋子的地方放上红色棋子,最后剩下的地方全都填上蓝色棋子

#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e2+10;
char mp[maxn][maxn];
void solve(int x, int y, int n) {
    mp[x][y] = 'W';
    if (x-2>=0 && y+1<n) 
    mp[x-2][y+1] = 'B';
    if (x-1>=0 && y+2<n) 
    mp[x-1][y+2] = 'B';
    if (x+2<n && y+1<n) 
    mp[x+2][y+1] = 'B';
    if (x+1<n && y+2<n)
    mp[x+1][y+2] = 'B';
    if (x+2<n && y-1>=0) 
    mp[x+2][y-1] = 'B';
    if (x+1<n && y-2>=0) 
    mp[x+1][y-2] = 'B';
    if (x-2>=0 && y-1>=0) 
    mp[x-2][y-1] = 'B';
    if (x-1>=0 && y-2>=0) 
    mp[x-2][y-1] = 'B';
}
int main(void) {
    int n;
    while(~scanf("%d", &n)) {
        for (int i = 0; i<n; i+=2)
            for (int j = 0; j<n; j+=2) {
                if (!mp[i][j]) solve(i, j, n);
            }
        for (int i = 0; i<n; ++i)
            for (int j = 0; j<n; ++j) {
                if (!mp[i][j]) mp[i][j] = 'W';
            }
        for (int z = 0; z<n; ++z) printf("%s\n", mp[z]);
        zero(mp);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/shuitiangong/p/12431700.html