Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)

Posted ydddd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)相关的知识,希望对你有一定的参考价值。

链接:

https://codeforces.com/contest/1221/problem/B

题意:

You are given a chess board with n rows and n columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.

A knight is a chess piece that can attack a piece in cell (x2, y2) from the cell (x1, y1) if one of the following conditions is met:

|x1?x2|=2 and |y1?y2|=1, or
|x1?x2|=1 and |y1?y2|=2.
Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).

A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.

思路:

画个3x3的图就行了, 上下左右不同即可.

代码:

#include <bits/stdc++.h>
using namespace std;

int main()

    char col[5] = "WB";
    int n;
    cin >> n;
    for (int i = 0;i < n;i++)
    
        for (int j = 0;j < n;j++)
        
            cout << col[(i+j)%2];
        
        cout << endl;
    

    return 0;

以上是关于Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27