21349_Puzzle

2022-5-16 18:19| 发布者: Hocassian| 查看: 42| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505180764199-Problem List-采集的数据-后羿采集器.html

Pro.ID

21349

Title

Puzzle

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21349

AC

1

Submit

1

Ratio

100.00%

时间&空间限制

  • Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 131072/65536 K (Java/Others)
  • 描述

    Sam loves all kinds of puzzles. Recently he received a very special puzzle - a grid of N x M squares, each square is occupied either by a red or by a blue pebble. The puzzle is controlled by several buttons.

    Each row of the grid has its corresponding black button. When you press a black button, a complicated mechanism of the puzzle flips the colors of all pebbles in the row corresponding to that button (all red pebbles in this row become blue and vice versa).

    Each column of the grid has its corresponding white button. When you press exactly two white buttons simultaneously, the puzzle mechanism exchanges the contents of the two columns corresponding to those buttons without changing the order of the pebbles in the columns.

    Sam has found the puzzle very interesting. Unfortunately, he lent it to his daughter Ann yesterday. She was able to understand the idea of the puzzle very quickly and she gave him this teasing task. She drew two arrangements - initial and final and she changed the colors of the pebbles according to the initial arrangement. Sam's task is to decide whether there exists a sequence of puzzle operations which transforms the initial arrangement of the puzzle to the final arrangement.

    输入

    The input file contains several blocks of input data. The first line of the input file contains K - the number of blocks. The first line of each block contains integers N and M. Each of the next N lines contain M words (either RED or BLUE), describing the initial Ann's arrangement of the colors of the pebbles. One blank line follows. The next N lines contain M words corresponding to the final arrangement of the colors.

    输出

    Description

    Sam loves all kinds of puzzles. Recently he received a very special puzzle - a grid of N x M squares, each square is occupied either by a red or by a blue pebble. The puzzle is controlled by several buttons.

    Each row of the grid has its corresponding black button. When you press a black button, a complicated mechanism of the puzzle flips the colors of all pebbles in the row corresponding to that button (all red pebbles in this row become blue and vice versa).

    Each column of the grid has its corresponding white button. When you press exactly two white buttons simultaneously, the puzzle mechanism exchanges the contents of the two columns corresponding to those buttons without changing the order of the pebbles in the columns.

    Sam has found the puzzle very interesting. Unfortunately, he lent it to his daughter Ann yesterday. She was able to understand the idea of the puzzle very quickly and she gave him this teasing task. She drew two arrangements - initial and final and she changed the colors of the pebbles according to the initial arrangement. Sam's task is to decide whether there exists a sequence of puzzle operations which transforms the initial arrangement of the puzzle to the final arrangement.

    Input
    The input file contains several blocks of input data. The first line of the input file contains K - the number of blocks. The first line of each block contains integers N and M. Each of the next N lines contain M words (either RED or BLUE), describing the initial Ann's arrangement of the colors of the pebbles. One blank line follows. The next N lines contain M words corresponding to the final arrangement of the colors.
    Output
    The output file contains K lines, the i-th line corresponds to the i-th block of the input data. Each line contains either YES or NO, the answer to the Ann's question.
    Sample Input
    2
    3 4
    BLUE RED BLUE RED
    RED BLUE BLUE RED
    BLUE BLUE BLUE BLUE

    BLUE RED BLUE RED
    RED RED BLUE BLUE
    BLUE BLUE BLUE BLUE
    2 2
    BLUE BLUE
    BLUE RED

    RED RED
    RED RED
    Sample Output
    YES
    NO
    Hint
    In the first block of the input data it suffices to use the black button for the second row and then to press the white buttons for the first and the third columns simultaneously.
    Source

    样例输入

    2
    3 4
    BLUE RED BLUE RED
    RED BLUE BLUE RED
    BLUE BLUE BLUE BLUE

    BLUE RED BLUE RED
    RED RED BLUE BLUE
    BLUE BLUE BLUE BLUE
    2 2
    BLUE BLUE
    BLUE RED

    RED RED
    RED RED

    样例输出

    YES
    NO

    提示

    In the first block of the input data it suffices to use the black button for the second row and then to press the white buttons for the first and the third columns simultaneously.

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部