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

Solution:

#include 
#include 
using namespace std;

class TurtleGame
{
public:
    string getwinner(vector 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 board;
    board.push_back("..");
    board.push_back("..");
    cout << t.getwinner(board) << endl;

    return 0;
}




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


小朋友学TopCoder(8):SRM726 DIV2 500-point_第1张图片
wechat.jpg

你可能感兴趣的:(小朋友学TopCoder(8):SRM726 DIV2 500-point)