编程介的小学生 2017-10-15 05:51 采纳率: 20.5%
浏览 1354
已采纳

Forgetful

Description

Each Sunday Mrs. Mahtaj who is an old woman goes to David Church and after the Sunday pray she comes back home. The traffic center has a complicated rule for closing crossroads that Mrs. Mahtaj can't understand. She is a forgetful woman who can only memorize the path from her house to church. The streets of her city are vertical or horizontal, the same as a grid with the squares of the same size. So she memorizes a path by a string of F (Forward), B (Backward), L (Left) and R (Right). For example, if there is no closed crossroad and Mahtaj is in crossroad (1,0) and faces east, if the string is BRFRLFL she reaches the crossroad (0,4). His son, Khashayar, decides to help her finding a path that can be used both for going from their house to the church and for coming back from the church to their house and does not pass any closed crossroad. I.e. Mahtaj should be able to go from her house to the church and from the church to her house by just one string. Help Khashayar to find such a path. When Mrs. Mahtaj starts the path from her house, she faces east and when she starts from the church she faces west.
Input

The input consists of several test cases. Each test case begins with a line containing m and n, the number of vertical and horizontal lines (streets) in the grid, which are in range 1 to 100. The second line of a test case contains two pairs of integer, which are x and y coordinates of the source (Mrs. Mahtaj's house) and x and y coordinates of the destination (David church). The horizontal and vertical lines in the grid are indexed from left to right and bottom to up from 0, so coordinates can be expressed using the indices. The third line of a test case contains a single numbe r N, which is the number of closed crossroads. It follows by N lines that each line contains x and y coordinates of a closed crossroad. The test case with m=n=0 indicates the end of the input file.
Output

The output for each test case is "YES" if there is such path and otherwise "NO". Output for each test case must be written on a separate line and the test case with m=n=0 has no output.
Sample Input

3 3
0 0 2 2
2
1 2
2 1
6 5
0 0 5 4
5
3 0
3 2
2 2
0 2
5 2
0 0
Sample Output

NO
YES

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-31 01:45
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了