360 笔试 全AC 思路鬼决的解法记录

笔试结束后上答案
其实想明白了,就特别简单
吐槽一下,测评做了一半,另一半一点没看就没时间了。。
第二题还有问题,中途还换了题目。。

第一题 寻找子串

直接去找单个字符出现的次数即可

#include <iostream>
#include <vector>
using namespace std;
int main() {
    string str;
    cin >> str;
    vector<int> arr(26, 0);
    int res = 0;
    for(auto &it:str) res = max(res, ++arr[it-'a']);
    cout << res << endl;
    return 0;
}

第二题 散步

吐槽一下,刚开始题目出错。。
维护两个 hash 表,一个代表当前点的情况,一个代表走完 D 步的情况

#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> arr(M);
    for(int i=0; i<M; i++)
        cin >> arr[i];
    unordered_set<int> hashSet;
    // 刚开始,有 N 种可能
    for(int i=1; i<=N; i++)
        hashSet.insert(i);

    for(int i=0; i<M; i++) {
        // 走完当前这一步可能的结果
        unordered_set<int> temp;
        for(auto &it:hashSet) {
            // 当前点向左或向右仍在范围内,则放到哈希表中
            if(it + arr[i] >= 1 && N >= it + arr[i])
                temp.insert(it + arr[i]);
            if(it - arr[i] >= 1 && N >= it - arr[i])
                temp.insert(it - arr[i]);
        }
        // 更新 哈希表
        swap(temp, hashSet);
    }

    cout << hashSet.size() << endl;

    return 0;
}
#360公司##笔试题目##题解#
全部评论
求散步代码
点赞 回复 分享
发布于 2019-08-31 17:52
求子串代码,
点赞 回复 分享
发布于 2019-08-31 17:52
第二题啥意思,看了半天没看懂
点赞 回复 分享
发布于 2019-08-31 17:53
散步样例N代表道路长度,也是数轴上点的数量,怎么理解?道路长度不是数轴上点的数量减1?
点赞 回复 分享
发布于 2019-08-31 17:56
求散步代码
点赞 回复 分享
发布于 2019-08-31 17:57
没懂子串的解法啥意思
点赞 回复 分享
发布于 2019-08-31 18:16
  30分钟的测评 我真是服了  就做了一个数学思维,然后 剩下逻辑一点没看 醉了
点赞 回复 分享
发布于 2019-08-31 19:01

相关推荐

03-10 20:35
已编辑
武汉大学 C++
点赞 评论 收藏
分享
评论
3
10
分享

创作者周榜

更多
牛客网
牛客企业服务