• Waterloo Local Contest 2019 (22 June, 29 September)


    https://www.jisuanke.com/contest/11360/challenges 

    其他题慢慢补

    C. Pawn‘s Revenge

    You are playing a special chess game against a professor and you've almost lost: the only piece you have left is a king. The professor just left the room to take a call, so you decided to cheat a little bit and put some extra pawns on the board so that each of opponent's pieces is under attack. As a reminder, a pawn attacks the two diagonally adjacent squares to the upper-left and upper-right of itself and a king attacks the eight adjacent squares (including the diagonally adjacent ones). You cannot put one piece on top of another piece. What is the smallest number of pawns you need to accomplish this task?

    Input

    The first row contains NNN, the dimension of the board, with 8≤N≤10008 ≤ N ≤ 10008≤N≤1000. The game is played on an NNN by NNN chessboard. The next NNN lines have NNN symbols each describing the board. The symbol - means that the square is empty, * denotes a professor's piece and K denotes your king. Your pawns move upward (i.e. towards rows that appear earlier in the input).

    Output

    Output a line containing one number, the smallest number of pawns needed to attack all of the professor's chess pieces, or −1 if it is impossible to do so.

    样例输入复制

    8

    -*-*----

    --------

    --------

    --------

    -----*K-

    --------

    --*-----

    --------

    样例输出复制

    2

    首先清掉K周围的*,然后遍历棋盘,对于每个*可以选左下或者右下,如果都能选的话尽可能选右下,然后把右下位置能清掉的*打标记,如果都不能放的话说明不行。

    代码又写挫了...

    #include <bits/stdc++.h>
    using namespace std;
    char mmap[1005][1005] = {'.'};
    bool ok[1005][1005] = {0};
    int n;
    int main()
    {
        cin >> n;
        int ans = 0;
        bool flag = 1;
        for(int i = 1; i <= n; i++) scanf("%s", mmap[i] + 1);
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(mmap[i][j] == 'K')
                {
                    ok[i - 1][j - 1] = ok[i - 1][j] = ok[i - 1][j + 1] = ok[i][j - 1] = ok[i][j + 1] = ok[i + 1][j - 1] = ok[i + 1][j] = ok[i + 1][j + 1] = 1;
                }
            }
        }
        //for(int i = 1; i <= n; i++) printf("%s
    ",mmap[i] + 1);
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(mmap[i][j] == '*' && !ok[i][j])
                {
                    if(mmap[i + 1][j - 1] == '-' && (mmap[i + 1][j + 1] != '-'))//可处理越界 
                    {
                        ans++;
                        mmap[i + 1][j - 1] = 'S';
                        ok[i][j] = ok[i][j - 2] = 1;
                    }
                    else if(mmap[i + 1][j + 1] == '-' && (mmap[i + 1][j - 1] != '-'))
                    {
                        ans++;
                        mmap[i + 1][j + 1] = 'S';
                        ok[i][j] = ok[i][j + 2] = 1;
                    }
                    else if(mmap[i + 1][j - 1] == '-' && mmap[i + 1][j + 1] == '-')
                    {
                        ans++;
                        mmap[i + 1][j + 1] = 'S';//?
                        ok[i][j] = ok[i][j + 2] = 1;
                    }
                    else
                    {
                        flag = 0;
                        break;
                    }
                }
            }
        }
        if(flag)
        {
            cout << ans << endl;
        }
        else cout << -1 << endl;
        return 0;
    }
    //5
    //--*--
    //*--*-
    //-----
    //--*K-
    //-----
  • 相关阅读:
    汇编中寄存器及其用处
    直接打印则需要调用PrintDocumnt.Print()方可打印,否按在对话框中点【打印】但不会有反应
    操作另一窗体的变量事件
    System.Windows.Forms.ListControl.SelectedValue.get 返回 null
    combox的selectedValue初始值注意事项
    vs2017中EF6.4无法导入到PM中,应使用EF6.2或6.1.1
    去除 Datetime的字段会自动赋默认值0001-1-1 0:00:00
    EF使用问题备忘
    EF中自定义连接字符串
    C#如何改变DataTable中的数据?
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13352512.html
Copyright © 2020-2023  润新知