CF 538D (Weird Chess-Inverse Calculation)

Source: Internet
Author: User

CF 538D (Weird Chess-Inverse Calculation)

 

D. Weird Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.

Igor's chessboard is a square of sizeN? ×?NCells. igor decided that simple rules guarantee success, that's why his game will have only one type of pieces. besides, all pieces in his game are of the same color. the possible moves of a piece are described by a set of shift vectors. the next passage contains a formal description of available moves.

Let the rows of the board be numbered from top to bottom and the columns be numbered from left to right from 1N. Let's assign to each square a pair of integers (X,?Y)-The number of the corresponding column and row. Each of the possible moves of the piece is defined by a pair of integers (Dx,?Dy); Using this move, the piece moves from the field (X,?Y) To the field (X? +?Dx,?Y? +?Dy). You can perform the move if the cell (X? +?Dx,?Y? +?Dy) Is within the boundaries of the board and doesn't contain another piece. Pieces that stand on the cells other (X,?Y) And (X? +?Dx,?Y? +?Dy) Are not important when considering the possibility of making the given move (for example, like when a knight moves in usual chess ).

Igor offers you to find out what moves his chess piece can make. he placed several pieces on the board and for each unoccupied square he told you whether it is attacked by any present piece (I. e. whether some of the pieces on the field can move to that cell ). restore a possible set of shift vectors of the piece, or else determine that Igor has made a mistake and such situation is impossible for any set of shift vectors.

Input

The first line contains a single integerN(1? ≤?N? ≤? 50 ).

The nextNLines containNCharacters each describing the position offered by Igor.J-Th character ofI-Th string can have the following values:

  • O-in this case the field (I,?J) Is occupied by a piece and the field may or may not be attacked by some other piece;
  • X-in this case field (I,?J) Is attacked by some piece;
  • .-In this case field (I,?J) Isn' t attacked by any piece.

    It is guaranteed that there is at least one piece on the board.

    Output

    If there is a valid set of moves, in the first line print a single word 'yes' (without the quotes ). next, print the description of the set of moves of a piece in the form of a (2N? -? 1 )? ×? (2N? -? 1) board, the center of the board has a piece and symbols 'X' mark cells that are attacked by it, in a format similar to the input. see examples of the output for a full understanding of the format. if there are several possible answers, print any of them.

    If a valid set of moves does not exist, print a single word 'no '.

    Sample test (s) input
    5oxxxxx...xx...xx...xxxxxo
    Output
    YES....x........x........x........x....xxxxoxxxx....x........x........x........x....
    Input
    6.x.x..x.x.x..xo..xx..ox..x.x.x..x.x.
    Output
    YES.....................................x.x.......x...x........o........x...x.......x.x.....................................
    Input
    3o.xoxxo.x
    Output
    NO
    Note

    In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight.



     

    Obtain the attack range as much as possible, and check whether it is the same as the source image.

     

     

     

    #include
       
        #include
        
         #include
         
          #include#include
          
           #include
           
            #include
            
             #include
             
              #include
              
               #include
               
                using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i
                
                 =0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (100+10)#define MP make_pairlong long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}typedef long long ll;int n;char s[MAXN];int a[MAXN][MAXN];bool b[MAXN][MAXN]={0};int d[MAXN][MAXN];vector
                 
                   > v;int &cx=n,&cy=n;int main(){//freopen("d.in","r",stdin);//freopen(".out","w",stdout);cin>>n;For(i,n){scanf("%s",s+1);For(j,n) {switch (s[j]){case'o':a[i][j]=2; v.push_back(MP(i,j)) ; break;case'x':a[i][j]=1 ; break;case'.':a[i][j]=0 ; break;}}}d[cx][cy]=2;For(i,2*n-1)For(j,2*n-1){if (i==cx&&j==cy) continue;int dx=i-cx,dy=j-cy;bool flag=1;for(vector
                  
                    >::iterator it=v.begin();it!=v.end();it++){int x=it->first,y=it->second;if (1<=x+dx&&x+dx<=n&&1<=y+dy&&y+dy<=n) if (!a[x+dx][y+dy]){flag=0;break;}}d[i][j]=flag;}For(i,2*n-1)For(j,2*n-1){if (i==cx&&j==cy) continue;if (!d[i][j]) continue;int dx=i-cx,dy=j-cy;for(vector
                   
                     >::iterator it=v.begin();it!=v.end();it++){int x=it->first,y=it->second;if (1<=x+dx&&x+dx<=n&&1<=y+dy&&y+dy<=n) b[x+dx][y+dy]=1;}}For(i,n)For(j,n)if (a[i][j]!=2)if (b[i][j]^a[i][j]) {cout<<"NO"<
                    
                     

     

     

     

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.