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

相关推荐

点赞 评论 收藏
分享
Twilight_m...:表格简历有点难绷。说说个人看法: 1.个人基本情况里好多无意义信息,什么婚姻状况、健康状况、兴趣爱好、户口所在地、身份证号码、邮政编码,不知道的以为你填什么申请表呢。 2.校内实践个人认为对找工作几乎没帮助,建议换成和测开有关的项目,实在没得写留着也行。 3.工作经历完全看不出来是干什么的,起码看着和计算机没啥关系,建议加强描述,写点你在工作期间的实际产出、解决了什么问题。 4.个人简述大而空,看着像AI生成,感觉问题最大。“Python,C,C++成为我打造高效稳定服务的得力工具”、“我渴望凭借自身技术知识与创新能力,推动人工智能技术的应用发展,助力社会实现智能化转型”有种小学作文的美感。而且你确定你个人简述里写的你都会嘛?你AI这块写的什么“深入研究”,发几篇顶会的硕博生都不一定敢这么写。而且你AI这块的能力和软测也完全无关啊。个人简述建议写你对哪些技术栈、哪些语言、哪些生产工具的掌握,写的有条理些,而且最好是和测开强相关的。
点赞 评论 收藏
分享
评论
13
29
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务