8.15 米哈游服务器开发笔试投票 + 全A代码


我投的服务器端开发,三道算法题,分别是ab凑字符数,周期数组,排雷,总体来说还是比较简单的,算法岗应该和我的题目不一样。。。

A 其实ab就相当于左右括号,这题就是判断括号是否合法,用个类似栈的结构判断即可
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        string str;
        cin>>str;
        int left = 0;
        int len = str.length();
        bool succ = true;
        for(int i=0;i<len;i++){
            if(str[i] =='a')
                left++;
            else{
                if(left == 0)
                    succ = false;
                else
                    left--;
            }
        }
        if(succ&&left == 0)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    return 0;
}

B 这个题最终形态就是奇数位都是一样的数字,偶数位也是一样的数字,我只要找到奇数偶数位各自出现次数最多的数,那么这个数组的最终形态就是这两个最多的数字
#include <bits/stdc++.h>

using namespace std;
map<int,int>id;
int cnt[50005];
int num[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);

    int now = 0;
    for(int i=1;i<=n;i+=2){
        int d = id[num[i]];
        if(d == 0)
        {
            id[num[i]] = ++now;
            d = now;
        }
        cnt[d]++;
    }
    int large = 0;
    for(int i=1;i<=now;i++)
        large = max(large,cnt[i]);
    int ans = n/2 - large;
    if(n%2 == 1)
        ans++;
    memset(cnt,0,sizeof(cnt));
    id.clear();

    now = 0;
    for(int i=2;i<=n;i+=2){
        int d = id[num[i]];
        if(d == 0)
        {
            id[num[i]] = ++now;
            d = now;
        }
        cnt[d]++;
    }
    large = 0;
    for(int i=1;i<=now;i++)
        large = max(large,cnt[i]);
    ans = ans + (n/2 - large);
    printf("%d\n",ans);
    return 0;
}

C 几乎是bfs裸题,判断一下当前点是否可以排雷即可,也就是向八个方向走能否走到地雷上
#include <bits/stdc++.h>

using namespace std;

char road[105][105];
int vis[105][105];
int dirx[4] = {0,0,1,-1};
int diry[4] = {1,-1,0,0};
int judgex[8] = {0,0,1,-1,-1,-1,1,1};
int judgey[8] = {1,-1,0,0,-1,1,-1,1};
queue<pair<int,int>>q;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m,x1,y1,x2,y2;
        scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)
                cin>>road[i][j];
        }
        memset(vis,0,sizeof(vis));
        while(!q.empty())
            q.pop();
        q.push(pair<int,int>(x1,y1));
        vis[x1][y1] = 1;
        int small = 0x3f3f3f3f;
        while(!q.empty()){
            pair<int,int>now = q.front();
            q.pop();
            for(int i=0;i<8;i++){
                int nx = now.first + judgex[i];
                int ny = now.second + judgey[i];
                if(nx<=0||ny<=0||nx>n||ny>m||road[nx][ny]=='#')
                    continue;
                if(nx == x2&&ny == y2){
                    small = vis[now.first][now.second];
                    break;
                }
            }
            if(small != 0x3f3f3f3f)
                break;
            for(int i=0;i<4;i++){
                int nx = now.first + dirx[i];
                int ny = now.second + diry[i];
                if(nx<=0||ny<=0||nx>n||ny>m||road[nx][ny]=='#'||vis[nx][ny]!=0)
                    continue;
                vis[nx][ny] = vis[now.first][now.second] + 1;
                q.push(pair<int,int>(nx,ny));
            }
        }

        if(small == 0x3f3f3f3f)
            printf("-1\n");
        else
            printf("%d\n",(x1*x2)^(small-1)^(y1*y2));
    }
    return 0;
}


#米哈游笔试##笔试题目##米哈游#
全部评论
算法第三题为啥我一直0%。本地测试一直对的...
2 回复 分享
发布于 2021-08-15 21:57
这第三题老是数组越界,过0%,吐了
1 回复 分享
发布于 2021-08-15 22:36
选择题太难了…差不多都不会,全是瞎猜…但算法题实在简单的出乎意料,全部行数加在一起都比雷火笔试第三题代码行数少🤣
1 回复 分享
发布于 2021-08-15 21:51
咋会有3这个选项呢……
1 回复 分享
发布于 2021-08-15 21:10
排名第一的央企成员企业招聘啦,南京,深圳皆岗,内推码yangj008 https://www.nowcoder.com/discuss/714257
点赞 回复 分享
发布于 2021-08-21 10:33
第一题我直接暴力哈哈
点赞 回复 分享
发布于 2021-08-16 12:02
投的前端考一堆c++😰
点赞 回复 分享
发布于 2021-08-16 11:14
大佬路过比AK的人还多,从统计上讲,大佬不屑于米哈游😥
点赞 回复 分享
发布于 2021-08-16 10:12
第一题可以直接不停地replace("ab","")就完事了,括号匹配感觉想复杂了
点赞 回复 分享
发布于 2021-08-15 23:18
代码A了两道,第三道本地写完了上去这个读写搞晕了直接人没了。 然后选择题真是rlgl,我投的图像算法问我这个简直了除了sql 和部分c++基本乱做的。 最后问答3d检测还行,图像检索那个什么鬼,有懂的指点下看的什么文章吗
点赞 回复 分享
发布于 2021-08-15 22:41
有大佬帮忙看看我第三题的代码吗。。卡在30%。是不是不能直接在地图上改,我把visit过的坐标直接改成了井号 。按说BFS模板写过多少次了 不会有错啊。。 核心代码: boolean reach = false; int step = 0; Queue<int[]> queue = new LinkedList<>(); queue.offer(new int[]{x1, y1}); map[x1][y1] = '井&(13607)#39;; while (!queue.isEmpty() && !reach) {     int sz = queue.size();     step++;     for (int i = 0; i < sz; i++) {         int[] cur = queue.poll();         int x = cur[0], y = cur[1];         for (int j = 0; j < 4; j++) {             int newX = x + dir[j][0], newY = y + dir[j][1];             if (newX < 0 || newX >= n || newY < 0 || newY >= m || map[newX][newY] == '井&(13607)#39;) continue;             map[newX][newY] = '井&#39;;             if (Math.abs(newX - x2) <= 1 && Math.abs(newY - y2) <= 1){                 reach = true;             }             queue.offer(new int[]{newX, newY});         }     } } if(reach){     System.out.println(((x1 + 1) * (x2 + 1)) ^ step ^ ((y1 + 1) * (y2 + 1))); } else{     System.out.println(-1); }
点赞 回复 分享
发布于 2021-08-15 22:40
那个,有问答题吗?我咋没看到
点赞 回复 分享
发布于 2021-08-15 22:34
选择确实不会啊 纯瞎蒙 编程A了两个第三个非得说我没return 0我调了半天也不明白啥意思
点赞 回复 分享
发布于 2021-08-15 22:26
求问第三题用dfs,测试用例过了但是提交后0%可能是什么原因?
点赞 回复 分享
发布于 2021-08-15 22:22
求问第一题为什么卡在13%我用了两种方法都卡在13%
点赞 回复 分享
发布于 2021-08-15 22:16
蹲一个第三题,之前阿里笔试也是这道,给我整不会了
点赞 回复 分享
发布于 2021-08-15 22:13
大佬,20多个选择3道算法你怎么做这么快啊。。。
点赞 回复 分享
发布于 2021-08-15 22:10
最后一题,那个距离的计算公示是 (x1*x2) ^ t ^ (y1*y2),但是案例里给的 1^0^4应该等于1不应该等于0啊,是我理解错了吗
点赞 回复 分享
发布于 2021-08-15 22:06
第一题不是和leetcode的合法括号一样逻辑吗?我按照那个写,为什么只有百分之13的通过率呀?有没有大佬指点一下,万分感谢
点赞 回复 分享
发布于 2021-08-15 22:04
吐了,第三题脑子昏掉了没写完
点赞 回复 分享
发布于 2021-08-15 22:01

相关推荐

评论
7
40
分享

创作者周榜

更多
牛客网
牛客企业服务