zoom 8.10 笔试

zoom 8.10 笔试

第一题就是建树 dfs一边

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace  std;
using ll= long long;
using pii =pair<int,int> ;

const int N=1e5+10;

int n;
char str[N];
int h[N],e[N<<1],ne[N<<1],idx;
bool st[N];

void add(int x,int y){
    e[idx]=y,ne[idx]=h[x],h[x]=idx++;
}

struct Node{
    int id,x,y;
};

ll bfs(){
    ll res=0;
    queue<Node> q;
    q.push({1,0,0});
    while(q.size()){
        auto cur=q.front();q.pop();
        if(st[cur.id]) continue;
        if(str[cur.id]=='R') cur.x++;
        else cur.y++;
        res+=abs(cur.x-cur.y);
        st[cur.id]=true;
        for(int i=h[cur.id];~i;i=ne[i]){
            int v=e[i];
            if(st[v]) continue;
            q.push({v,cur.x,cur.y});
        }
    }
    return res;
}


int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>str[i];
    memset(h,-1,sizeof h);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        add(x,y),add(y,x);
    }

    cout<<bfs()<<endl;
    return 0;
}












第二题 并查集 记录下连通块大小即可

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace  std;
using ll= long long;
using pii =pair<int,int> ;

const int N=1e5+10;

int n,m;

unordered_map<string,int> name;
unordered_map<string ,vector<int>> h;

int f[N],si[N];
int idx=0;

int get(int x){
    if(x!=f[x]) f[x]=get(f[x]);
    return f[x];
}

void merge(int x,int y){
    int fx=get(x),fy=get(y);
    if(fx!=fy) {
        f[fx]=fy;
        si[fy]+=si[fx];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>m;

    for(int i=1;i<N;i++) {
        f[i]=i;
        si[i]=1;
    }

    while(m--){
        int op;
        cin>>op;
        string s;
        if(op==1){
            cin>>s>>n;
            for(int i=0;i<n;i++){
                string t;
                cin>>t;
                if(name.count(t)) h[s].push_back(name[t]);
                else {
                    name[t]=++idx;
                    h[s].push_back(name[t]);
                }
            }
            for(int i=0;i<h[s].size()-1;i++){
                merge(h[s][i],h[s][i+1]);
            }
        }else if(op==2) {
            cin>>s;
            if(!h.count(s)) cout<<"error"<<endl;
            else{
                int fx=get(h[s][0]);
                cout<<si[fx]-h[s].size()<<endl;
            }
        }
    }
    return 0;
}












#Zoom##ZOOM笔试##做完zoom2023秋招笔试,人麻了#
全部评论
我就喜欢这种考数据结构的题,那种贪心回溯啥的总是想不出
2 回复 分享
发布于 2022-08-10 20:35
大佬牛逼
1 回复 分享
发布于 2022-08-10 20:33
大佬 第二题的思路能说的详细点吗
1 回复 分享
发布于 2022-08-10 20:33
第一题卡96%,第二题知道是并查集,一时间忘了如何下手0%,寄!😃
1 回复 分享
发布于 2022-08-10 20:34
牛逼
1 回复 分享
发布于 2022-08-10 20:48
第二题看成了要返回推荐股票的名称,然后就不会做了😂
1 回复 分享
发布于 2022-08-10 21:48
牛啊
点赞 回复 分享
发布于 2022-08-10 20:34
点赞 回复 分享
发布于 2022-08-10 20:38
楼主就是牛
点赞 回复 分享
发布于 2022-08-10 20:39
不是 不能用c++嘛😓
点赞 回复 分享
发布于 2022-08-10 20:42
牛逼
点赞 回复 分享
发布于 2022-08-10 20:45
第二题用的不带权重的并查集,后面超时想加权来不及了😭
点赞 回复 分享
发布于 2022-08-10 20:46
请问大伙,这代码为什么会超内存呢?只过了46%
点赞 回复 分享
发布于 2022-08-10 20:48
真牛啊 自己是嘎了
点赞 回复 分享
发布于 2022-08-10 20:53
铁铁,考虑考虑咱网易呗,三大事业群都在向你招手哦,速来速来 https://www.nowcoder.com/discuss/1009725
点赞 回复 分享
发布于 2022-08-10 21:48
你好,可以看一下我主页讨论帖。亿联网络,厂商,通信行业独角兽,薪资福利行业领先,有兴趣的话可以直接去我讨论帖内推链接,hr直通车https://neitui.italent.cn/yealink/sharejobs?shareId=5e36baaf-1cf5-47cd-8973-6294f8c3ef68在帖子下留言(姓名+岗位方便查进度哈)
点赞 回复 分享
发布于 2022-08-13 19:46

相关推荐

不愿透露姓名的神秘牛友
2024-12-30 18:02
程序员牛肉:1.可以标记一下自己的学校是985,有一些hr可能没想到你这个院校是985的。 2.简历所呈现出来的能力还是有点差的,苍穹外卖+黑马点评。这在java技术域里面也就是刚学三四个月的样子,大厂现在招人少,小厂又更加希望你能直接过来干活。就你简历上呈现出来的能力,确实是有点难找,肉眼可见的不懂技术。 第一个项目中:简单的使用redis也算是亮点嘛?使用jwt,threadlocal也算是亮点?你不就是调了几个包嘛?Nginx作为服务器也能写出来,这不是前端的活嘛? 第二个项目中:分布式锁+mq消息队列+Lua队列。真没啥好问的。属于面试官看一眼就阳痿的简历,没有任何想提问的欲望。 我给你建议是好好的挖一挖这个项目吧,其实苍穹外卖和黑马点评这两个项目很不错了,只不过是太烂大街了导致面试官没啥问的兴趣,所以不太推荐写简历上。
点赞 评论 收藏
分享
02-02 20:25
门头沟学院 Java
数学转码崽:八股文也算是前人总结的精华,但是因为全是结果导向,你光背不去理解它背后的深层原理和这样做的原因,反而忽略了程序员最该重视的过程导向。推荐你不会的就去多问ai,比如我当时背的时候,concurrenthashmap底层原理常见八股网站都会讲,但是我不理解为什么它去用synchronize锁节点,为什么不用reentrantlock去锁节点。面试官问我你为什么觉得synchronize在这个场景下性能更好呢?虽然面试官可能也不确定清楚,但是你可以尝试给他解答,让他看见你的思考,这才是最重要的,毕竟你没实习,你的项目你也无法证明是你自己思考的产物,那就在别的地方体现你的能力
点赞 评论 收藏
分享
评论
13
29
分享

创作者周榜

更多
牛客网
牛客企业服务