zoukankan      html  css  js  c++  java
  • Game with string CodeForces

    虽然只是B题,还是div2的

    但感觉挺有意思,所以写一篇博客记录一下

    最初的想法是利用DP去做,f[s]=true表示字符串s对应先手赢,否则对应后手赢,大致想了下发现是指数级别的算法,看了下范围直接pass掉

    然后就接着想,发现如果两个相等的字符被消掉之后,相等字符的周边靠过来,如果还能消除的话他们就是相等,一想这不就是括号匹配?

    然后问题就转化为了寻找合法括号字段的长度

    然后就简单了

    竟然是用栈来做!!!

    #include<cstdio>
    #include<map>
    #include<set>
    #include<queue>
    #include<string>
    #include<stack>
    #include<vector>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    //#define endl "
    "
    #define inf 0x3f3f3f3f
    #define me(a,b) memset(a,b,sizeof(a))
    
    string s;
    stack<char> st;
    int main()
    {
        cin>>s;
        int cnt=0;
        for(auto i:s){
            if(st.empty()) st.push(i);
            else {
                char c=st.top();
                if(c==i) cnt++,st.pop();
                else st.push(i);
            }
        }
        if(cnt&1) puts("Yes");
        else puts("No");
    
    }
  • 相关阅读:
    按钮常用
    MySQL常用Json函数
    MySQL所有函数及操作符
    MySQL常用时间函数
    MySQL常用聚合函数
    Shiro整合Spring
    Shiro集成Web
    Shrio授权验证详解
    Shrio认证详解+自定义Realm
    Shiro入门
  • 原文地址:https://www.cnblogs.com/033000-/p/10463845.html
Copyright © 2011-2022 走看看