9.23 快手笔试

1、用两个栈来回倒腾、同时记录对应的次数 100%;
#include <bits/stdc++.h>

using namespace std;

class FreqStack{
    public:
    unordered_map<int, int> cnts;
    stack<int> s;
};

int main(){
    FreqStack fs;
    int num;
    while(cin >> num){
        if(num == 0){
            if(fs.s.size() == 0){
                cout << -1 << endl;
                continue;
            }
            stack<int> s_2;
            int max_cnts = 0;
            for(auto it: fs.cnts){
                max_cnts = max(max_cnts, it.second);
            }
            
            while(!fs.s.empty()){
                if(fs.cnts[fs.s.top()] == max_cnts){
                    cout << fs.s.top() << endl;
                    fs.cnts[fs.s.top()] -= 1;
                    fs.s.pop();
                    break;
                }
                s_2.push(fs.s.top());
                fs.s.pop();
            }
            
            while(!s_2.empty()){ 
                fs.s.push(s_2.top());
                s_2.pop();
            }
            
        }else{
            fs.s.push(num);
            fs.cnts[num] += 1;
        }
    }
    
    return 0;
}
2、力扣原题,不说了 100%;
3、起手就是一个暴力回溯骗分;20%;头疼交了
#include <bits/stdc++.h>

using namespace std;

vector<vector<long>> path(1, vector<long>(2));
vector<vector<long>> nums;
long ret = LONG_MAX;

void callback(int idx){
    if(idx == path.size()){
        long cur_num = 1;
        long cur_ret = 0;
        for(int i=0; i< path.size(); i++){
            cur_ret = max(cur_num/path[i][1], cur_ret);
            cur_num *= path[i][0];
        }
        ret = min(cur_ret, ret);
        return;
    }
    for(int i=idx; i< path.size(); i++){
        callback(i+1);
        swap(path[i], path[idx]);
        callback(i+1);
        swap(path[i], path[idx]);
    }
}


int main(){
    long n;
    cin >> n;
    cin >> path[0][0] >> path[0][1];
    for(int i=0; i< n; i++){
        vector<long> num_i(2);
        cin >> num_i[0] >> num_i[1];
        path.push_back(num_i);
    }
    vector<bool> used(n, false);
    callback(1);
    cout << ret;
    return 0;
}
值得一提的是,网上有原题....;
#快手笔试#
全部评论
楼主,请问一下,第三题网上原题怎么搜啊
点赞
送花
回复
分享
发布于 2022-09-23 23:04 广东
第二题是什么题目呀
点赞
送花
回复
分享
发布于 2022-09-24 12:23 上海
滴滴
校招火热招聘中
官网直投
谢谢老哥的题解!能不能请问下你的官网状态变成啥了,我一道都没a
点赞
送花
回复
分享
发布于 2022-09-26 16:17 瑞士

相关推荐

4 7 评论
分享
牛客网
牛客企业服务