B. Knights
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a chess board with ? rows and ? 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 (?2, ?2) from the cell (?1, ?1) if one of the following conditions is met:

|?1−?2|=2 and |?1−?2|=1, or
|?1−?2|=1 and |?1−?2|=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.

Input
The first line contains one integer ? (3≤?≤100) — the number of rows (and columns) in the board.

Output
Print ? lines with ? characters in each line. The ?-th character in the ?-th line should be W, if the cell (?, ?) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.

Example
inputCopy
3
outputCopy
WBW
BBB
WBW
Note
In the first example, there are 8 duels:

the white knight in (1, 1) attacks the black knight in (3, 2);
the white knight in (1, 1) attacks the black knight in (2, 3);
the white knight in (1, 3) attacks the black knight in (3, 2);
the white knight in (1, 3) attacks the black knight in (2, 1);
the white knight in (3, 1) attacks the black knight in (1, 2);
the white knight in (3, 1) attacks the black knight in (2, 3);
the white knight in (3, 3) attacks the black knight in (1, 2);
the white knight in (3, 3) attacks the black knight in (2, 1).

题意: 骑士能攻击到8个方向不同颜色的骑士。有W,B两种颜色的骑士,怎样安排骑士的位置使得互相攻击的骑士数目最多。

思路: 涨姿势了,一行BWBW,一行WBWB就可以了。把图画出来就可以看到了。因为骑士能攻击到曼哈顿距离为3的点,这样安排刚好使得曼哈顿距离为3的点,都是不同颜色的。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>using namespace std;int a[105][105];
int main()
{int n;scanf("%d",&n);for(int i = 1;i <= n;i++){for(int j = 1;j <= n;j++){if(i & 1){if(j & 1)printf("W");else printf("B");}else{if(j & 1)printf("B");else printf("W");}}printf("\n");}return 0;
}

Knights CodeForces - 1221B相关推荐

  1. Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)

    补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...

  2. Codeforces 994B. Knights of a Polygonal Table

    解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...

  3. Codeforces Round #518 (Div. 2): F. Knights(神题)

    题意: 一个无限大的棋盘,初始往这个棋盘中放n个骑士(骑士走日字,和马一样),之后如果存在一个点可以被4个骑士一步到达,那么就往这个格子上再放一个马,并且无限继续下去,直到不存在任意一个点可以被4个骑 ...

  4. 【Codeforces】1080C Masha and two friends (棋盘染色)

    http://codeforces.com/problemset/problem/1080/C 给定一个棋盘,(1,1)的位置是白色,观察可以知道,如果横纵坐标之和是偶数,那么是白色,奇数的话就是黑色 ...

  5. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  6. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  7. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  8. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  9. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

最新文章

  1. python中filter函数的使用
  2. python用中文怎么说-震惊!!!python可以用中文写代码
  3. Openjudge2729 Blah数集(单调队列)
  4. python在windows安装paramiko模块
  5. ie和谷歌在java中空格兼容,谷歌和IE浏览器的兼容性问题,相同的html结构竟然在两个浏览器不一样...
  6. 行泊ADAS摄像头前装搭载同比增长54.15%,TOP10供应商领跑
  7. 基于java的病历管理系统设计与实现
  8. C# 将PDF转为Word、Html、XPS、SVG、PCL、PS——基于Spire.Cloud.PDF.SDK
  9. macd的VB计算机程序,大智慧自选股实时同步到通达信VB小软件简单升级
  10. 51单片机 wifi模块代码编写的历程 esp8266
  11. LS1028使用原生RGMII软件修改方案
  12. 这样的员工一定会成为高管
  13. 半导体设备英文缩写_涨知识!晶圆制造主要设备一览。
  14. 倒序输出字符串,如输入i love you,则输出you love i
  15. 使用idea运行CS项目后“客户端页面加载不出来“的解决方法
  16. 骑士游历问题【JAVA板】代码详细流
  17. MarkdownPad安装及基本配置
  18. Bioconductor分析基因芯片数据第五章
  19. 百度人脸识别测试环境配置教程
  20. Linux下安装navicat

热门文章

  1. Oracle 批量插入(insert all into)
  2. 移动硬盘读不出来怎么办?试试这么做!
  3. Bee+创始人贾凡出席“粤港澳大湾区青年论坛”并做主题发言
  4. [译] WWDC 2018:关于iOS 12、iPad Pro、新MacBook及更多产品的所有预测
  5. (转)Moodle平台简介
  6. 同期对比图_Excel展示两组同期数据,这种左右对比图真好看,只需六步搞定
  7. 一头扎进Shiro 笔记 Shiro 支持特性
  8. 非常详细的SIP协议总结
  9. [Swift]LeetCode1135. 最低成本联通所有城市 | Connecting Cities With Minimum Cost
  10. xpwifi热点设置android,windowsXP设置wifi热点教程