zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    入门系列4
    入门系列3
    入门系列2
    入门系列1
    sql进阶-筛选库表中数据为空的表
    sql进阶-删除所有的视图
    sql序列(2) sql语句功能表
    sql序列(5)事务
    sql序列(4)存储过程
    KVM虚拟化介绍
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11625451.html
Copyright © 2011-2022 走看看