• CodeForces


    Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.

    The game is played on the following field.

    Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.

    You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.

    A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.

    Input

    First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell.

    The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right.

    It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.

    Output

    Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.

    Example
    Input
    ... ... ...
    ... ... ...
    ... ... ...
    
    ... ... ...
    ... ... ...
    ... x.. ...
    
    ... ... ...
    ... ... ...
    ... ... ...
    6 4
    
    Output
    ... ... ... 
    ... ... ... 
    ... ... ... 
    
    ... ... ... 
    ... ... ... 
    ... x.. ... 
    
    !!! ... ... 
    !!! ... ... 
    !!! ... ... 
    
    
    Input
    xoo x.. x..
    ooo ... ...
    ooo ... ...
    
    x.. x.. x..
    ... ... ...
    ... ... ...
    
    x.. x.. x..
    ... ... ...
    ... ... ...
    7 4
    
    Output
    xoo x!! x!! 
    ooo !!! !!! 
    ooo !!! !!! 
    
    x!! x!! x!! 
    !!! !!! !!! 
    !!! !!! !!! 
    
    x!! x!! x!! 
    !!! !!! !!! 
    !!! !!! !!! 
    
    
    Input
    o.. ... ...
    ... ... ...
    ... ... ...
    
    ... xxx ...
    ... xox ...
    ... ooo ...
    
    ... ... ...
    ... ... ...
    ... ... ...
    5 5
    
    Output
    o!! !!! !!! 
    !!! !!! !!! 
    !!! !!! !!! 
    
    !!! xxx !!! 
    !!! xox !!! 
    !!! ooo !!! 
    
    !!! !!! !!! 
    !!! !!! !!! 
    !!! !!! !!! 
    
    
    Note

    In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.

    In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.

    In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.


    题意不太难懂就是有点长,太烦人。经过翻译和自己的理解知道题意大概是这样的:给你一幅图有一个最大格子里有九个中格子,每一个中格子里有九个小格子。两个人依次放棋子。规则是:第一个人可以任意放,但是之后的人必须放在上一个人放的 小格 子 的 位 置  对 应 中 格 子 的 ' . ' ;也就是把上一个人的格子放大,对应的中格子;

    当对应的中格子满了的时候,这个人就可以随便放。

    给你的这个图,不需要判断是否符合游戏规则,只需要根据最后一步的位置(题目所给的x,y)进行下一步操作。


    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<queue>
    #include<map>
    #include<stack>
    #define maxn 10005
    #define inf 0x3f3f3f3f
    #define ll long long
    #define mod 1000000009
    const double eps=1e-8;
    const double PI=acos(-1.0);
    using namespace std;
    char s[20][20];
    int judge(int a,int b){//判断小格子对应中格子的位置
        a%=3,b%=3;
        if(a==0&&b==0)return 1;
        if(a==0&&b==1)return 2;
        if(a==0&&b==2)return 3;
        if(a==1&&b==0)return 4;
        if(a==1&&b==1)return 5;
        if(a==1&&b==2)return 6;
        if(a==2&&b==0)return 7;
        if(a==2&&b==1)return 8;
        if(a==2&&b==2)return 9;
    }
    bool check(int p){//判断是否放满;
        int i,j;
        if(p==1)i=0,j=0;
        if(p==2)i=0,j=3;
        if(p==3)i=0,j=6;
        if(p==4)i=3,j=0;
        if(p==5)i=3,j=3;
        if(p==6)i=3,j=6;
        if(p==7)i=6,j=0;
        if(p==8)i=6,j=3;
        if(p==9)i=6,j=6;
        int I=i+3,J=j+3;
        int flag=0;
        for(int x=i;x<I;x++){
            for(int y=j;y<J;y++){
                if(s[x][y]=='.'){flag=1;s[x][y]='!';}
            }
        }
        if(flag==0)
            return false;
        else
        return true;
    }
    int main(){
        char ss[20];
        for(int i=0;i<3;i++){
            gets(ss);int l=0;
        for(int j=0;j<strlen(ss);j++){
                if(ss[j]!=' ')s[i][l++]=ss[j];
            }
        }getchar();
        for(int i=3;i<6;i++){
           gets(ss);int l=0;
        for(int j=0;j<strlen(ss);j++){
                if(ss[j]!=' ')s[i][l++]=ss[j];
            }
        }getchar();
        for(int i=6;i<9;i++){
            gets(ss);int l=0;
        for(int j=0;j<strlen(ss);j++){
                if(ss[j]!=' ')s[i][l++]=ss[j];
            }
        }
        int x,y;cin>>x>>y;
        int ans=judge(x-1,y-1);
        if(check(ans)){
            for(int i=0;i<9;i++){
                    if(i!=0&&(i)%3==0)cout<<endl;
                for(int j=0;j<9;j++){
                    if(j!=0&&j%3==0)cout<<" ";
                    cout<<s[i][j];
                }cout<<endl;
            }
        }
        else{
            for(int i=0;i<9;i++){if(i!=0&&i%3==0)cout<<endl;
                for(int j=0;j<9;j++){
                    if(j!=0&&j%3==0)cout<<" ";
                    if(s[i][j]=='.')s[i][j]='!';
                    cout<<s[i][j];
                }cout<<endl;
    
            }
        }
    }
    






  • 相关阅读:
    FFmpeg 播放 RTSP/Webcam 流
    Kafka的工作原理及过程
    Zookeeper--典型应用场景解决方案
    Zookeeper--理论及客户端
    使用jasypt加密配置的时候,报错:DecryptionException: Unable to decrypt
    kubebuilder实战之六:构建部署运行
    kubebuilder实战之五:operator编码
    kubebuilder实战之四:operator需求说明和设计
    kubebuilder实战之三:基础知识速览
    kubebuilder实战之二:初次体验kubebuilder
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053258.html
Copyright © 2020-2023  润新知