2024年美团春招技术岗第一批笔试

#include<bits/stdc++.h>
using namespace std;
const int N=220;
int a[N][N],s[N][N];
signed main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            char c;
            cin>>c;
            int x=c-'0';
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+x;
        }
    }
    for(int sz=1;sz<=n;sz++){
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                int L=i-sz,R=j-sz;
                if(L<0||R<0)continue;
                int x=s[i][j]-s[i][R]-s[L][j]+s[L][R];
                int sum=sz*sz;
                if(x==sum-x)ans++;
            }
        }
        cout<<ans<<'\n';
    }
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int a[N],n,q,sum,cnt0;
signed main() {
    cin>>n>>q;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        sum+=x;
        if(x==0)cnt0++;
    }
    while(q--){
        int l,r,maxx=0,minn=0;
        cin>>l>>r;
        maxx=sum+r*cnt0;
        minn=sum+l*cnt0;
        cout<<minn<<" "<<maxx<<'\n';
    }
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int a,b,c,n,k;
signed main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        char c;
        cin>>c;
        if(c=='M')a++;
        else if(c=='T')b++;
        else c++;
    }
    int ans=(a+b+k);
    cout<<min(ans,n);
}

#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct UF
{
    // 题给范围n太大, 用map存储
    map<int, int> pa;

    int find(int a)
    {
        if (pa[a] != a)
            pa[a] = find(pa[a]);
        return pa[a];
    }

    bool isConnect(int a, int b)
    {
        return find(a) == find(b);
    }

    void add(int x, int y)
    {
        pa[find(x)] = find(y);
    }
};

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    // 存储关系
    UF uf;
    set<pair<int, int>> relations;
    while (m --)
    {
        int a, b;
        cin >> a >> b;

        // 初始化
        uf.pa[a] = a;
        uf.pa[b] = b;
        // 使用set和强制规定a < b, 避免重边
        if (a > b)
            swap(a, b);
        relations.insert({a, b});
    }

    // 存储事件并维护关系
    vector<vector<int>> acts;
    while (q --)
    {
        int op, a, b;
        cin >> op >> a >> b;

        // 初始化
        uf.pa[a] = a;
        uf.pa[b] = b;

        if (a > b)
            swap(a, b);      
        // 删除操作, 合法就删除, 不合法就跳过
        if (op == 1)
        {
            if (relations.find({a, b}) != relations.end())
                relations.erase({a, b});
            else
                continue;
        }

        vector<int> tmp = {op, a, b};
        acts.emplace_back(tmp);
    }

    // 用剩余的关系建立并查集
    for (auto& [a, b] : relations)
        uf.add(a, b);

    // 逆向遍历事件
    reverse(acts.begin(), acts.end());
    stack<string> ans;
    for (auto& act : acts)
    {
        int op = act[0], a = act[1], b = act[2];
        if (op == 1)
            uf.add(a, b);
        else
        {
            if (uf.isConnect(a, b))
                ans.push("Yes");
            else
                ans.push("No");
        }
    }

    // 输出答案
    while (!ans.empty())
    {
        cout << ans.top() << '\n';
        ans.pop();
    }
}v

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
int n,k,a[N],b[N],ans;
int check(int l,int r){
    int A=a[l-1]+a[n]-a[r];
    int B=b[l-1]+b[n]-b[r];
    // cout<<"L="<<l<<" R="<<r<<" A="<<A<<" B="<<B<<endl;
    return min(A,B)>=k;
}
signed main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        while(x%5==0)a[i]++,x/=5;
        // cout<<" a["<<i<<"]="<<a[i];
        a[i]+=a[i-1];
        while(x%2==0)b[i]++,x/=2;
        // cout<<" b["<<i<<"]="<<b[i];
        b[i]+=b[i-1];
    }
    for(int i=1;i<=n;i++){
        int l=i,r=n;
        while(l<r){
            int mid=(l+r+1)/2;
            if(check(i,mid))l=mid;
            else r=mid-1;
        }
        // cout<<" i="<<i<<" l="<<l<<endl;
        if(check(i,l))ans+=l-i+1;
    }
    cout<<ans;
}

全部评论

相关推荐

我也想要红名timeline————————3.18投递3.22笔试(2/3)3.23ai面3.24约一面3.26一面3.27约二面3.28二面4.2offer一面:面试官人很好,上来先自我介绍了一下,然后说了下部门业务。然后我自我介绍,然后项目拷打,问的比较细,然后八股,问的也很细1.知道namespace吗?他的中文名是什么?它的作用是什么?2.模版知道吗?他最大的作用是什么?他和define的区别是什么?3.虚函数怎么实现的?如果一个类有虚函数,你创建一个实例,那他都会有虚函数表吗?4.修改用户权限的指令,以及rwx的数字5.ls知道吗?后面加什么参数可以看到隐藏文件6.top知道是用来干啥的吗?7.怎么查看一个文件内容?查看大数据文件时,用哪个命令8.redis数据结构有哪些?除了这五种还知道其他种类吗?9.除了mysql还用过其他数据库吗?除了json还知道其他通信协议吗?10.http端口号,https端口号11.tcp&nbsp;udp区别?12.redis发布订阅功能消息没有持久化,该怎么处理?13.static关键词用在哪些变量前?他们分别是多会儿初始化的?两个cpp文件,各有一个static全局变量,谁先初始化?14.move的作用?谈谈你对深浅拷贝的理解15.http常用的命令有哪些?301状态码是啥意思?16.四次挥手最后为什么需要time&nbsp;wait?17.给你一个字符串,返回当中最长的回文子串&nbsp;原题,但是原题中规定给的字符串长度必须大于等于1,面试官没有规定,我没考虑长度为0的情况,指正了一下我18.给两个非空链表,两个链表数据求和,返回求和以后的链表头。然后面试官说虚拟头节点最后记得delete一下。用的美团的编程界面,核心模式,代码没跑,让面试官看就好了最后反问二面:进来让你选择一个你比较感兴趣和熟悉的项目,然后让你介绍一下这个项目,接下来就开始了四十分钟的项目拷打,其中半个小时是关于你熟悉的项目的拷打,十分钟左右是关于另外一个项目的了解。然后问了几个开放性问题1.有没有团队合作过?团队合作出现过什么问题?出现问题解决不了的时候该怎么办?2.有没有了解过ai,该怎么用?你用过哪些编码ai插件。然后就进入了反问环节,反问差不多进行了十分钟左右,全程55分钟结束美团面试体验真的很好,面试官尊重候选人,流程推进的又快
查看20道真题和解析
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务