zoukankan      html  css  js  c++  java
  • 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-
    //-----
  • 相关阅读:
    格式控制符
    sort快速排序法
    堆积排序
    oracle常用命令
    C#中int和System.Int32理解总结
    IIS 7.5中的配置
    WPF循序渐进:XAML入门 .
    怎样找到excel两列之间同行相同的数据
    pl/sql functions and cbo costing
    Oracle 学习纲要
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13352512.html
Copyright © 2011-2022 走看看