|
| 1 | + |
| 2 | + |
| 3 | +//A queen is standing on an chessboard. |
| 4 | +//The chess board's rows are numbered from to , going from bottom to top. |
| 5 | +//Its columns are numbered from to , going from left to right. Each square is referenced by a tuple, , describing the row, , and column, , where the square is located. |
| 6 | + |
| 7 | +//The queen is standing at position say(rq,cq) |
| 8 | +//In a single move, she can attack any square in any of the eight directions (left, right, up, down, and the four diagonals) |
| 9 | + |
| 10 | +#include<bits/stdc++.h> |
| 11 | +using namespace std; |
| 12 | +map<pair<int,int>,int>mp; |
| 13 | +//global declaration of variables |
| 14 | +int t=0,x,y,n,k; |
| 15 | +void check(int x,int y,int x2,int y2){ |
| 16 | +while(x<=n && x>0 && y<=n && y>0 && mp[{x,y}]==0){ |
| 17 | +x+=x2; |
| 18 | +y+=y2; |
| 19 | +t++; |
| 20 | +}} |
| 21 | + |
| 22 | +//driver program |
| 23 | + |
| 24 | +int main(){ |
| 25 | +cin>>n>>k; |
| 26 | +int x1,y1; |
| 27 | +cin>>x>>y; |
| 28 | + |
| 29 | +//we are making pair so as to mark the position of obstacles (here i am marking its position say mp[{x,y}]=1 so as to recognize the position of obsatcles |
| 30 | +//if there is obstacle present by the way i am checking this in <b>check</b>function |
| 31 | +//we can move to the consecutive location until no obstacles present |
| 32 | + |
| 33 | +while(k--){ |
| 34 | +cin>>x1>>y1; |
| 35 | +mp[{x1,y1}]=1; |
| 36 | +} |
| 37 | + |
| 38 | +//these are the positions the queen can move up,down,left,right,and the 4 diagonals from its current positions say(x,y) |
| 39 | +check(x+1,y,1,0);//right direction |
| 40 | +check(x-1,y,-1,0);//left direction |
| 41 | +check(x,y+1,0,1);//up direction |
| 42 | +check(x,y-1,0,-1);//down direction |
| 43 | +//the adjacent 4 diagonals directions |
| 44 | +check(x-1,y-1,-1,-1); |
| 45 | +check(x+1,y+1,1,1); |
| 46 | +check(x+1,y-1,1,-1); |
| 47 | +check(x-1,y+1,-1,1); |
| 48 | +cout<<t; |
| 49 | +} |
0 commit comments