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;
}

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

时间: 2024-08-29 17:10:05

Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)的相关文章

Educational Codeforces Round 73 (Rated for Div. 2)

比赛链接:Educational Codeforces Round 73 (Rated for Div. 2) 官方题解:Educational Codeforces Round 73 Editorial A. 2048 Game 题意 如果一个只包含 \(2\) 的幂次的集合,问能否从中选择一些数使得和为 \(2048\). 思路 不断合并直到凑到 \(2048\). 代码 #include <bits/stdc++.h> using namespace std; int main() {

Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again

题目链接:http://codeforces.com/contest/1221/problem/D 题意:给一个序列,要求修改某些位置的数字,使得这个序列的相邻的数不相等,每次修改,只能使得某个数字加一,每次修改的代价为b[i],求最小所需的代价. 解题思路:经过简单分析,我们可以知道,每个数字最多只需要修改两次,那么我们定义dp[i][j]使得前j个数字相邻数字不等的最小代价,且最后一个数字修改了i次.那么答案即为min{dp[0][n],dp[1][n],dp[2][n]}. #includ

Educational Codeforces Round 73 (Rated for Div. 2) A. 2048 Game

链接: https://codeforces.com/contest/1221/problem/A 题意: You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two. You may perform any number (possibly, zero) operations wi

Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again(DP)

链接: https://codeforces.com/contest/1221/problem/D 题意: You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is ai. You think that the fence is great if there is no pair of adjacent boards having

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w