题目链接: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.
InputThe 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).
OutputPrint "YES" (without quotes) if Bob can get from
You can print each letter in any case (upper or lower).
Examples8
4 4
1 3
3 1
YES
8
4 4
2 3
1 6
NO
8
3 5
1 2
6 1
NO
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.
In the second case, the queen watches the fourth rank, and the king has no means of crossing it.
In the third case, the queen watches the third file.
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 }