zoukankan      html  css  js  c++  java
  • [Luogu 3952] NOIP2017 时间复杂度

    [Luogu 3952] NOIP2017 时间复杂度

    <题目链接>


    一年的时间说长不长,说短,也不短。

    一年之内无数次觉得难得可怕的题目,原来也就模拟这么回事儿。

    #include <cstdio>
    #include <iostream>
    #include <set>
    #include <stack>
    #include <string>
    
    int T; 
    
    struct Layer
    {
        std::string name; 
        int state; 
        Layer(std::string name, int state): name(name), state(state){}
    }; 
    
    int Solve(std::string s)
    {
        if(s == "O(1)")
            return 0; 
        int ans = 0; 
        for(int i = 4; s[i] != ')'; ++i)
            ans = ans * 10 + s[i] - '0'; 
        return ans; 
    }
    
    int Number(std::string s)
    {
        if(s[0] == 'n')
            return 0; 
        int ans = 0; 
        for(int i = 0; s[i]; ++i)
            ans = ans * 10 + s[i] - '0'; 
        return ans; 
    }
    
    int main(void)
    {
        scanf("%d", &T); 
        while(T--)
        {
            bool right = true; 
            int n, ans, cur = 0, fact = 0; 
            std::set<std::string> Name; 
            std::stack<Layer> S; 
            std::string a[5]; 
            scanf("%d", &n); 
            std::cin >> a[0]; 
            ans = Solve(a[0]); 
            for(int i = 1; i <= n; ++i)
            {
                std::cin >> a[1]; 
                if(a[1] == "F")
                {
                    for(int i = 2; i <= 4; ++i)
                        std::cin >> a[i]; 
                    if(right && !Name.count(a[2]))
                    {
                        int state, x = Number(a[3]), y = Number(a[4]); 
                        if((!S.empty() && S.top().state == -1) || (!x && y) || (x > y && y))
                            state = -1; 
                        else if(x && !y)
                        {
                            state = 1; 
                            ++cur; 
                        }
                        else
                            state = 0; 
                        Name.insert(a[2]); 
                        S.push(Layer(a[2], state)); 
                    }
                    else
                        right = false; 
                }
                else if(right)
                {
                    if(!S.empty())
                    {
                        Layer t = S.top(); 
                        Name.erase(t.name); 
                        S.pop(); 
                        fact = std::max(fact, cur); 
                        if(t.state == 1)
                            --cur; 
                    }
                    else
                        right = false; 
                }
            }
            if(!S.empty())
                right = false; 
            if(!right)
                puts("ERR"); 
            else
                puts(ans == fact ? "Yes" : "No"); 
        }
        return 0; 
    }
    

    谢谢阅读。

  • 相关阅读:
    【go语言】Windows下go语言beego框架安装
    分页
    MongoDB用户与权限管理
    MongoDB安装在Centos7下安装
    centos7安装mysql5.7.33 tar包方式
    文件路径分隔符
    python之批量打印网页为pdf文件
    Python驱动SAP GUI完成自动化(五)
    动态内存与智能指针
    关联容器
  • 原文地址:https://www.cnblogs.com/Capella/p/9853948.html
Copyright © 2011-2022 走看看