[codeforces538D]Weird Chess

试题描述

Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.

Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of pieces. Besides, all pieces in his game are of the same color. The possible moves of a piece are described by a set of shift vectors. The next passage contains a formal description of available moves.

Let the rows of the board be numbered from top to bottom and the columns be numbered from left to right from 1 to n. Let's assign to each square a pair of integers (x, y) — the number of the corresponding column and row. Each of the possible moves of the piece is defined by a pair of integers (dx, dy); using this move, the piece moves from the field (x, y) to the field (x + dx, y + dy). You can perform the move if the cell (x + dx, y + dy) is within the boundaries of the board and doesn't contain another piece. Pieces that stand on the cells other than (x, y) and (x + dx, y + dy)are not important when considering the possibility of making the given move (for example, like when a knight moves in usual chess).

Igor offers you to find out what moves his chess piece can make. He placed several pieces on the board and for each unoccupied square he told you whether it is attacked by any present piece (i.e. whether some of the pieces on the field can move to that cell). Restore a possible set of shift vectors of the piece, or else determine that Igor has made a mistake and such situation is impossible for any set of shift vectors.

输入

The first line contains a single integer n (1 ≤ n ≤ 50).

The next n lines contain n characters each describing the position offered by Igor. The j-th character of the i-th string can have the following values:

  • o — in this case the field (i, j) is occupied by a piece and the field may or may not be attacked by some other piece;
  • x — in this case field (i, j) is attacked by some piece;
  • . — in this case field (i, j) isn't attacked by any piece.

It is guaranteed that there is at least one piece on the board.

输出

If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2n - 1) × (2n - 1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar to the input. See examples of the output for a full understanding of the format. If there are several possible answers, print any of them.

If a valid set of moves does not exist, print a single word 'NO'.

输入示例

.x.x..
x.x.x.
.xo..x
x..ox.
.x.x.x
..x.x.

输出示例

YES
...........
...........
...........
....x.x....
...x...x...
.....o.....
...x...x...
....x.x....
...........
...........
...........

数据规模及约定

见“输入

题解

我们把输入的地图叫“原图”,输出的图叫“攻击图”。

可以发现,对于“原图”中每个 'o',对于任意一个 '.' 的位置,它在“攻击图”中对应的位置也是 '.',因为这个 'o' 是不可能攻击到该位置的。

所以对于每个 'o',把所有 '.' 相对 'o' 的位置取个并,其它地方都是 'x',最后再大力 check 一波合法性就好了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 110
int n;
char Map[maxn][maxn], Att[maxn][maxn];
bool vis[maxn][maxn]; int main() {
memset(Att, 'x', sizeof(Att));
n = read();
for(int i = 1; i <= n; i++) scanf("%s", Map[i] + 1); Att[n][n] = 'o';
for(int i = 1; i <= (n << 1) - 1; i++) Att[i][n<<1] = '\0';
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) if(Map[i][j] == 'o')
for(int x = 1; x <= n; x++)
for(int y = 1; y <= n; y++) if(Map[x][y] == '.')
Att[n+x-i][n+y-j] = '.';
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) if(Map[i][j] == 'o')
for(int x = 1; x <= n; x++)
for(int y = 1; y <= n; y++)
if(Map[x][y] == 'x' && Att[n+x-i][n+y-j] == 'x') vis[x][y] = 1;
bool ok = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(Map[i][j] == 'x' && !vis[i][j]){ ok = 0; break; } if(!ok) return puts("NO"), 0;
puts("YES");
for(int i = 1; i <= (n << 1) - 1; i++) puts(Att[i] + 1); return 0;
}

[codeforces538D]Weird Chess的更多相关文章

  1. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  2. Codeforces Round #300 D. Weird Chess 水题

    D. Weird Chess Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/proble ...

  3. Codeforces Round #300 解题报告

    呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...

  4. hdu4405 Aeroplane chess

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

  6. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

  7. This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.

    -- :::] This application is modifying the autolayout engine from a background thread, which can lead ...

  8. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

随机推荐

  1. Web版简易五子棋

    前些时候把大三写的C++版五子棋改成Web板挂到了网上,具有一定傻瓜式智能,欢迎体验使用拍砖:http://www.zhentiyuan.com/Games/QuickFiveChess.aspx 现 ...

  2. Sublime折腾记录

    本文可以理解为FAQ,主要是为了大家GET一些技能,具体内容包括LICENSE.重置.Package Control的安装,其他内容以后可能补充... 最后说明一下自己的版本:Build 3114 L ...

  3. InvocationTargetException异常的深入研究-servlet的setAttribute与getAttribute

    在某项目中,前端jsp传入的用户id数据通过session域传入后台servlet进行处理的过程中,无意间出现了InvocationTargetException异常 前端部分代码如下:测试代码,非原 ...

  4. Docker下redis的主从配置

    1.拉取redis镜像docker pull redis2.启动3个redis容器服务,分别使用到6379.6380.6381端口docker run --name redis-6379 -p 637 ...

  5. TebsorFlow低阶API(五)—— 保存和恢复

    简介 tf.train.Saver 类提供了保存和恢复模型的方法.通过 tf.saved_model.simple_save 函数可以轻松地保存适合投入使用的模型.Estimator会自动保存和恢复 ...

  6. 细说PHP-5.3.4变量的引用赋值

    变量总是传值赋值.也就是说,当讲一个表达式的值赋予一个变量时,整个原始表达式的值被赋值到目标变量.这意味着,当一个变量的值赋予另个一变量时,改变其中一个变量的值,将不会影响到另一个变量.PHP中提供了 ...

  7. uva1614 Hell on the Markets

    贪心部分的理论依据:前i个数可以凑出1-sum[i]的所有整数. 证明:第二类数学归纳,n=1时成立,假设n=k之前所有项都成立,当n=k+1时.sum[k+1]=sum[k]+a[k+1].只需证明 ...

  8. Object.assign(o1, o2, o3) 对象 复制 合拼

    Object 对象方法学习之(1)—— 使用 Object.assign 复制对象.合并对象 合并对象 var o1 = {a: 1}; var o2 = {b: 2}; var o3 = {c: 3 ...

  9. 20道必须掌握的C++面试题

    20道必须掌握的C++面试题 在面试C++方面的工作时,经常会遇到各种面试题,这对应聘人员的知识掌握能力要求较高.本文将为大家带来的就是20道必须掌握的C++面试题,不要错过哦! 问1:请用简单的语言 ...

  10. Activiti6简明教程

    一.为什么选择Activiti 工作流引擎对比 二.核心7大接口.28张表 7大接口 (一)7大接口 RepositoryService:提供一系列管理流程部署和流程定义的API. RuntimeSe ...