码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-10-05 20:26:18      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:class   example   possible   hit   上下   its   codeforce   bit   https   

链接:

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(构造)

标签:class   example   possible   hit   上下   its   codeforce   bit   https   

原文地址:https://www.cnblogs.com/YDDDD/p/11625451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!