zoukankan      html  css  js  c++  java
  • 猿辅导 2019年 校招提前批笔试

    第一题

    就是让你解析一个串,这样子
    (AA(BB)2)3 -> AABBBBAABBBBAABBBB

    空间的话超过的话,我其实是可以用vector来优化的...233 (当场没做出来 哭了)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        int n;
        scanf("%d", &n);
        for (int x=0; x<n; x++) {
            string s; cin >> s;
            int i = 0, l = s.size();
            stack<string> st;
            while(i < l) {
                if(s[i] == '(') {
                    st.push("(");
                    i++;
                } else if(s[i] == ')') {
                    string ans = "";
                    while(!st.empty() && st.top() != "(") {
                        ans.insert(0,st.top());
                        st.pop();
                    }
    
                    st.pop();
                    st.push(ans);
                    i++;
                } else if(s[i] >= '0' && s[i] <= '9') {
                    int ans = 0;
                    while(i < l && s[i] >= '0' && s[i] <= '9') {
                        ans = ans * 10 + (s[i] - '0');
                        i++;
                    }
                    string ss = st.top();
                    st.pop();
                    string tmp;
                    for(int i=0; i<ans; i++)
                        tmp += ss;
                    st.push(tmp);
                } else {
                    string ss;
                    ss.push_back(s[i]);
                    st.push(ss);
                    i++;
                }
    
            }
    
            string res;
            while(!st.empty()) {
                res.insert(0, st.top());
                st.pop();
            }
            cout << res <<endl;
        }
        return 0;
    }
    

    第二题

    在矩阵里面搜 每次只能跳到比当前格子大的,然后有k次机会,可以跳小的.

    dfs(i,j,k) 代表 i,j 用了k次机会所跳到的...
    记忆化一下就求出来了
    死于初始值...

    第三题

    k个人, n次传递, 每次从一个人传到另外一个人,求最开始是自己 最后传回自己的方案数

    首先n-2次传递是任何一个人都可以, n-1次传递只能传到其他人(不是自己的人)那里

    因此 公式就是 ans = ((k-1)^(n-2) + k-2) % mod

    中间用快速幂求就可以了

  • 相关阅读:
    timeouts _ golang
    select.go
    channel directions _ golang
    channel synchronization _ golang
    channel _ buffering
    servlet:共享资源造成的线程冲突
    java:多线程的 共享资源冲突问题
    jsp:通过过滤器进行网页的资源管理
    jsp:通过Session控制登陆时间和内部页面的访问
    java:数据结构
  • 原文地址:https://www.cnblogs.com/Draymonder/p/11296459.html
Copyright © 2011-2022 走看看