题目链接:http://codeforces.com/problemset/problem/1033/A

Problem Description

Alice and Bob are playing chess on a huge chessboard with dimensions (bx,by). Alice thinks that as her queen is dominating the chessboard, victory is hers.

But Bob has made a devious plan to seize the victory for himself — he needs to march his king to she no longer moves any pieces around, and it is only Bob who makes any turns.

Bob will win if he can move his king from 8 adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen.

Find whether Bob can win or not.

Input

The first line contains a single integer 3≤n≤1000) — the dimensions of the chessboard.

The second line contains two integers 1≤ax,ay≤n) — the coordinates of Alice's queen.

The third line contains two integers 1≤bx,by≤n) — the coordinates of Bob's king.

The fourth line contains two integers 1≤cx,cy≤n) — the coordinates of the location that Bob wants to get to.

It is guaranteed that Bob's king is currently not in check and the target location is not in check either.

Furthermore, the king is not located on the same square as the queen (i.e. cy≠by).

Output

Print "YES" (without quotes) if Bob can get from 

You can print each letter in any case (upper or lower).

Examples
Input
8
4 4
1 3
3 1
Output
YES
Input
8
4 4
2 3
1 6
Output
NO
Input
8
3 5
1 2
6 1
Output
NO
Note

In the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.

In the first case, the king can move, for instance, via the squares (2,2) goes through check.

CF1033A. King Escape的题解

In the second case, the queen watches the fourth rank, and the king has no means of crossing it.

CF1033A. King Escape的题解

In the third case, the queen watches the third file.

CF1033A. King Escape的题解
思路:1.深度搜索。注意国王的移动规则。有八个方向。
     2.只需判断起点与终点是否在同一象限即可
解法1.(缺省)
 1 #include<stdio.h>
 2 int move[8][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
 3 int i,j,k,t;
 4 int goal_x,goal_y;
 5 int n;
 6 int map[1010][1010];
 7 int laft;
 8 int x1,x2,y2,y1;
 9 void dfs(int x,int y)
10 {
11     if(x==goal_x&&y==goal_y)
12     {
13         laft=1;
14         return;
15     }
16     int move_x,move_y;
17     for(int k=0;k<8;k++)
18     {
19         move_x=x+move[k][0];
20         move_y=y+move[k][1];
21         if(move_x>n||move_x<1||move_y>n||move_y<1)
22         {
23             continue;
24         }
25         if(move_x+move_y!=x1+y1&&move_x-move_y+n!=x1-y1+n&&move_x!=x1&&move_y!=y1&&map[move_x][move_y]==0)
26         {
27             map[move_x][move_y]=1;
28             dfs(move_x,move_y);
29         }
30     }
31     return;
32 }     
33 int main()
34 {
35     scanf("%d",&n);
36     scanf("%d%d",&x1,&y1);
37     scanf("%d%d",&x2,&y2);
38     scanf("%d%d",&goal_x,&goal_y);
39     dfs(x2,y2);
40     if(laft==0)
41         printf("NO\n");
42     else if(laft==1)
43         printf("YES\n");        
44 }
View Code(深搜)

相关文章:

  • 2021-09-26
  • 2021-11-19
  • 2021-08-22
  • 2021-06-18
  • 2021-11-04
  • 2021-09-26
  • 2022-03-09
  • 2022-12-23
猜你喜欢
  • 2021-10-15
  • 2021-10-06
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
相关资源
相似解决方案