题目链接:http://codeforces.com/problemset/problem/1033/A
Problem Description
Alice and Bob are playing chess on a huge chessboard with dimensions n×nn×n. Alice has a single piece left — a queen, located at (ax,ay)(ax,ay), while Bob has only the king standing at (bx,by)(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 (cx,cy)(cx,cy) in order to claim the victory for himself. As Alice is distracted by her sense of superiority, 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 (bx,by)(bx,by) to (cx,cy)(cx,cy) without ever getting in check. Remember that a king can move to any of the 88 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 nn (3≤n≤10003≤n≤1000) — the dimensions of the chessboard.
The second line contains two integers axax and ayay (1≤ax,ay≤n1≤ax,ay≤n) — the coordinates of Alice's queen.
The third line contains two integers bxbx and byby (1≤bx,by≤n1≤bx,by≤n) — the coordinates of Bob's king.
The fourth line contains two integers cxcx and cycy (1≤cx,cy≤n1≤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. ax≠bxax≠bx or ay≠byay≠by), and the target does coincide neither with the queen's position (i.e. cx≠axcx≠ax or cy≠aycy≠ay) nor with the king's position (i.e. cx≠bxcx≠bxor cy≠bycy≠by).
OutputPrint "YES" (without quotes) if Bob can get from (bx,by)(bx,by) to (cx,cy)(cx,cy) without ever getting in check, otherwise print "NO".
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,3)(2,3)and (3,2)(3,2). Note that the direct route through (2,2)(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 "); 42 else if(laft==1) 43 printf("YES "); 44 }
1 #include<stdio.h> 2 int map[1010][1010]; 3 int main() 4 { 5 int n,x1,y1,x2,y2,x,y,flag=0; 6 scanf("%d",&n); 7 scanf("%d%d",&x1,&y1); 8 scanf("%d%d",&x2,&y2); 9 scanf("%d%d",&x,&y); 10 if(x2<x1&&y2>y1&&x<x1&&y>y1||x2<x1&&y2<y1&&x<x1&&y<y1||x2>x1&&y2>y1&&x>x1&&y>y1||x2>x1&&y2<y1&&x>x1&&y<y1) 11 //判断是否在同一象限即可 12 flag=1; 13 if(flag) 14 printf("YES "); 15 else 16 printf("NO "); 17 return 0; 18 }