topcoders 666

早起切两水:

222:

class DevuAndGame
{
        public:

        int vis[55];
        int a[55];
        int dfs(int u)
        {
            if(u == -1) return 1;
            vis[u] = 1;
            int v = a[u];
            if(vis[v])
                return 0;

            return dfs(v);
        }

        string canWin(vector <int> nextLevel)
        {
            for(int i = 0; i < nextLevel.size(); i++)
                a[i] = nextLevel[i];

                memset(vis, 0,sizeof vis);
                int ans = dfs(0);
                if(ans) return "Win";
                else return "Lose";
        }
};


444:

class GoodString
{
        public:
        string isGood(string s)
        {
            int len = s.size();
            int cnt = 0;
            for(int i = 0; i < len; i++)
            {
                if(s[i] == 'a')
                    cnt++;
                else cnt--;
                if(cnt < 0) break;
            }
            if(cnt < 0 || cnt > 0)
                return "Bad";
            else return "Good";
        }
};



你可能感兴趣的:(ACM)