美文网首页数据结构和算法分享专题程序员C++
小朋友学TopCoder(8):SRM726 DIV2 500-

小朋友学TopCoder(8):SRM726 DIV2 500-

作者: 海天一树X | 来源:发表于2018-01-11 00:08 被阅读24次

    Solution:

    #include <iostream>
    #include <vector>
    using namespace std;
    
    class TurtleGame
    {
    public:
        string getwinner(vector<string> board)
        {
            const int N = board.size();
            const int M = board[0].size();
            int cnt  = 0;
    
            for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < M; j++)
                {
                    cnt += board[i][j] == '.';
                }
            }
    
            // Get the total remove count
            // N+M-1 means the minimum turtle-friendly board
            cnt -= (N + M - 1);
    
            // Hero win if remove count is odd, else he lose
            return cnt % 2 ? "Win" : "Lose";
        }
    };
    
    int main()
    {
        TurtleGame t;
        vector<string> board;
        board.push_back("..");
        board.push_back("..");
        cout << t.getwinner(board) << endl;
    
        return 0;
    }
    



    更多内容请关注微信公众号


    wechat.jpg

    相关文章

      网友评论

        本文标题:小朋友学TopCoder(8):SRM726 DIV2 500-

        本文链接:https://www.haomeiwen.com/subject/lpnanxtx.html