CF1236D.Alice and the Doll

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice got a new doll these days. It can even walk!

Alice has built a maze for the doll and wants to test it. The maze is a grid with nn rows and mm columns. There are kk obstacles, the ii-th of them is on the cell (xi,yi)(x_i, y_i), which means the cell in the intersection of the xix_i-th row and the yiy_i-th column.

However, the doll is clumsy in some ways. It can only walk straight or turn right at most once in the same cell (including the start cell). It cannot get into a cell with an obstacle or get out of the maze.

More formally, there exist 44 directions, in which the doll can look:

  1. The doll looks in the direction along the row from the first cell to the last. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x,y+1)(x, y + 1);
  2. The doll looks in the direction along the column from the first cell to the last. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x+1,y)(x + 1, y);
  3. The doll looks in the direction along the row from the last cell to first. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x,y−1)(x, y - 1);
  4. The doll looks in the direction along the column from the last cell to the first. While moving looking in this direction the doll will move from the cell (x,y)(x, y) into the cell (x−1,y)(x - 1, y).

.

Standing in some cell the doll can move into the cell in the direction it looks or it can turn right once. Turning right once, the doll switches it's direction by the following rules: 1→21 \to 2, 2→32 \to 3, 3→43 \to 4, 4→14 \to 1. Standing in one cell, the doll can make at most one turn right.

Now Alice is controlling the doll's moves. She puts the doll in of the cell (1,1)(1, 1) (the upper-left cell of the maze). Initially, the doll looks to the direction 11, so along the row from the first cell to the last. She wants to let the doll walk across all the cells without obstacles exactly once and end in any place. Can it be achieved?

爱丽丝最近得到了一个新娃娃,它甚至会走路!

爱丽丝为这个娃娃建造了一个迷宫并想测试它的能力。该迷宫是一个 nn 行 mm 列的网格。其中有 kk 个障碍物,第 ii 个障碍物位于单元格 (xi,yi)(x_i, y_i),即第 xix_i 行与第 yiy_i 列相交的单元格。

然而,这个娃娃在某些方面显得笨拙:它在同一个单元格(包括起始单元格)中最多只能直行或向右转一次。它不能进入有障碍物的单元格,也不能走出迷宫边界。

更严格地说,娃娃可能朝向以下 44 个方向之一:

  1. 娃娃沿行方向从第一个单元格朝向最后一个单元格看。在此方向移动时,娃娃将从单元格 (x,y)(x, y) 移动到单元格 (x,y+1)(x, y + 1);
  2. 娃娃沿列方向从第一个单元格朝向最后一个单元格看。在此方向移动时,娃娃将从单元格 (x,y)(x, y) 移动到单元格 (x+1,y)(x + 1, y);
  3. 娃娃沿行方向从最后一个单元格朝向第一个单元格看。在此方向移动时,娃娃将从单元格 (x,y)(x, y) 移动到单元格 (x,y−1)(x, y - 1);
  4. 娃娃沿列方向从最后一个单元格朝向第一个单元格看。在此方向移动时,娃娃将从单元格 (x,y)(x, y) 移动到单元格 (x−1,y)(x - 1, y)。

站在某个单元格中时,娃娃可以朝当前所面对的方向移动至相邻单元格,或者最多向右转一次。向右转一次意味着娃娃按如下规则切换其朝向:1→21 \to 2,2→32 \to 3,3→43 \to 4,4→14 \to 1。在同一个单元格中,娃娃最多只能执行一次向右转操作。

现在爱丽丝控制着娃娃的移动。她将娃娃放置在单元格 (1,1)(1, 1)(迷宫的左上角单元格),初始朝向为方向 11(即沿行从第一个单元格朝向最后一个单元格)。她希望娃娃恰好经过所有无障碍单元格一次,并最终停在任意位置。这能实现吗?

输入格式

The first line contains three integers nn, mm and kk, separated by spaces (1≤n,m≤105,0≤k≤1051 \leq n,m \leq 10^5, 0 \leq k \leq 10^5) — the size of the maze and the number of obstacles.

Next kk lines describes the obstacles, the ii-th line contains two integer numbers xix_i and yiy_i, separated by spaces (1≤xi≤n,1≤yi≤m1 \leq x_i \leq n,1 \leq y_i \leq m), which describes the position of the ii-th obstacle.

It is guaranteed that no two obstacles are in the same cell and no obstacle is in cell (1,1)(1, 1).

第一行包含三个整数 nn、mm 和 kk,以空格分隔(1≤n,m≤105, 0≤k≤1051 \leq n,m \leq 10^5,\ 0 \leq k \leq 10^5)——分别表示迷宫的尺寸以及障碍物的数量。

接下来的 kk 行描述障碍物,其中第 ii 行包含两个整数 xix_i 和 yiy_i,以空格分隔(1≤xi≤n, 1≤yi≤m1 \leq x_i \leq n,\ 1 \leq y_i \leq m),表示第 ii 个障碍物的位置。

保证任意两个障碍物不在同一格子中,且没有任何障碍物位于格子 (1,1)(1, 1)。

输出格式

Print 'Yes' (without quotes) if the doll can walk across all the cells without obstacles exactly once by the rules, described in the statement.

If it is impossible to walk across the maze by these rules print 'No' (without quotes).

如果玩偶能够按照题目描述的规则,恰好经过迷宫中所有无障碍单元格一次,则输出 Yes(不带引号)。

如果按照这些规则无法走完整个迷宫,则输出 No(不带引号)。

输入输出样例

  • 输入#1

    3 3 2
    2 2
    2 1

    输出#1

    Yes
  • 输入#2

    3 3 2
    3 1
    2 2

    输出#2

    No
  • 输入#3

    3 3 8
    1 2
    1 3
    2 1
    2 2
    2 3
    3 1
    3 2
    3 3

    输出#3

    Yes

说明/提示

Here is the picture of maze described in the first example:

In the first example, the doll can walk in this way:

  • The doll is in the cell (1,1)(1, 1), looks to the direction 11. Move straight;
  • The doll is in the cell (1,2)(1, 2), looks to the direction 11. Move straight;
  • The doll is in the cell (1,3)(1, 3), looks to the direction 11. Turn right;
  • The doll is in the cell (1,3)(1, 3), looks to the direction 22. Move straight;
  • The doll is in the cell (2,3)(2, 3), looks to the direction 22. Move straight;
  • The doll is in the cell (3,3)(3, 3), looks to the direction 22. Turn right;
  • The doll is in the cell (3,3)(3, 3), looks to the direction 33. Move straight;
  • The doll is in the cell (3,2)(3, 2), looks to the direction 33. Move straight;
  • The doll is in the cell (3,1)(3, 1), looks to the direction 33. The goal is achieved, all cells of the maze without obstacles passed exactly once.

以下是第一个样例中迷宫的图片:

在第一个样例中,玩偶可按如下方式行走:

  • 玩偶位于单元格 (1,1)(1, 1),朝向方向 11,直行;
  • 玩偶位于单元格 (1,2)(1, 2),朝向方向 11,直行;
  • 玩偶位于单元格 (1,3)(1, 3),朝向方向 11,右转;
  • 玩偶位于单元格 (1,3)(1, 3),朝向方向 22,直行;
  • 玩偶位于单元格 (2,3)(2, 3),朝向方向 22,直行;
  • 玩偶位于单元格 (3,3)(3, 3),朝向方向 22,右转;
  • 玩偶位于单元格 (3,3)(3, 3),朝向方向 33,直行;
  • 玩偶位于单元格 (3,2)(3, 2),朝向方向 33,直行;
  • 玩偶位于单元格 (3,1)(3, 1),朝向方向 33。目标达成:迷宫中所有无障碍单元格均被恰好经过一次。

输入解题思路,AI测评打分。不知道怎么写?

首页