9.4美团笔试(AK代码)

T1:DP

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 50;
const LL MOD = 998244353;
LL dp[N][2][2];//dp[i][j][k] 表示前i个字符 倒数第二个是j,倒数第一个是k的方案数。0表示a,1表示b
int main() {
    int n; cin >> n;
    if(n <= 3) {
        cout <<n * 2;
        return 0;
    }
    dp[3][0][0] = dp[3][1][1] = 2;
    dp[3][0][1] = dp[3][1][0] = 1;
    for(int i = 4; i <= n; i++) {
        dp[i][0][0] = (dp[i-1][0][0] + dp[i-1][1][0]) % MOD;
        dp[i][0][1] = dp[i-1][0][0];
        dp[i][1][0] = dp[i-1][1][1];
        dp[i][1][1] = (dp[i-1][0][1] + dp[i-1][1][1]) % MOD;
    }
    LL ans = 0;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++) {
            ans += dp[n][i][j];
            ans %=MOD;
        }
    }
    cout << ans;
    return 0;
}

/*
3

6
*/

T2:跑floyd

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e2+ 50;
const LL MOD = 998244353;
LL dp[N][2][2];
int f[N][N];
vector<int> e[N];
int main() {
    int n, m; cin >> n >> m;
    memset(f, 63, sizeof f);
    int limit = f[0][0];
    for(int i = 1; i <= n; i++) {
        f[i][i] = 0;
        int k; cin >> k;
        while(k--) {
            int x; cin >> x;
            e[x].push_back(i);
        }
    }
    for(int i = 1; i < N; i++){
        for(int j = 0; j < e[i].size(); j++) {
            for(int k = 0; k < e[i].size(); k++) {
                int S = e[i][j];
                int T = e[i][k];
                f[S][T] = f[T][S] = min(f[S][T], 1);
            }
        }
    }

    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(f[i][j] == limit) {
                f[i][j] = -1;
            }
            cout << f[i][j];
            if(j != n) {
                cout << ' ';
            }
        }
        cout << "\n";
    }
    return 0;
}
/*

3 2
1 1
2 1 2
1 2

0 1 2
1 0 1
2 1 0
*/

T3:变成ccccc...aaaaa..就行,倒着计数每个a后面有多少个c

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 50;
const LL MOD = 998244353;
LL dp[N][2][2];
int main() {
    int n; cin >> n;
    string s; cin >> s;
    LL ans = 0;
    int cnt_c = 0;
    for(int i = n-1; ~i; i--){
        cnt_c += s[i] == 'c';
        if(s[i] == 'a') {
            ans += cnt_c;
        }
    }
    cout << ans;
    return 0;
}
/*
4
acca

2
*/

T4:四元环计数

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e2 + 50;
const LL MOD = 998244353;
int mp[N][N];
vector<int>e[N], q[N];
int ID[N], du[N],RANK[N], num[N];
int main() {    
    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        ID[i] = i;
        for(int j = 1; j <= n; j++) {
          int x; cin >> x;
          if(x){
              e[i].push_back(j);
          }
        }
    }
    for(int i = 1; i <= n; i++) {
        du[i] = e[i].size();
    }
    sort(ID + 1, ID + n + 1,[](int a,int b) {
        if(du[a] == du[b]) {
            return a < b;
        }
        return du[a] < du[b] ;
    });
    LL ans = 0;
    for(int i = 1; i <= n; i++) {
        RANK[ID[i]] = i;
    }
    for(int i = 1; i <= n; i++) {
        for(int x : e[i]) {
            if(RANK[x] > RANK[i]) {
                q[i].push_back(x);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int x : e[i]) {
            for(int y : q[x]) {
                if(RANK[y] > RANK[i]) {
                    ans += num[y];
                    num[y]++;
                }
            }
        }
        for(int x : e[i]) {
            for(int y : q[x]) {
                if(RANK[y] > RANK[i]) {
                    num[y] = 0;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

/*

6
0 1 1 1 0 0
1 0 1 0 1 0
1 1 0 0 0 1
1 0 0 0 1 1
0 1 0 1 0 1
0 0 1 1 1 0

3
*/

T5:滑动窗口求区间最大/最小值 + 枚举

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 50;
const LL MOD = 998244353;
LL a[N];
int MAX[N], MIN[N];
deque<int> que, quee;
int main() {
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        while(!que.empty() && i - que.front() + 1 > m) que.pop_front();
        while(!que.empty() && a[i] >= a[que.back()] ) que.pop_back();
        que.push_back(i);
        if(i>=m) {
            MAX[i] = a[que.front()];
        }
    }

    for(int i = 1; i <= n; i++) {
        while(!quee.empty() && i - quee.front() + 1 > m) quee.pop_front();
        while(!quee.empty() && a[i] <= a[quee.back()] ) quee.pop_back();
        quee.push_back(i);
        if(i>=m) {
            MIN[i] = a[quee.front()];
        }
    }
    for(int i = 1; i <= n; i++) {
        a[i] += a[i-1];
    }
    int ans = -1;
    LL ave = 0;
    for(int i = m; i <= n; i++) {
        LL now = (a[i] - a[i-m] - MAX[i] - MIN[i]) ;
        if(now > ave) {
            ans = i - m + 1;
            ave = now;
        }
    }
    cout << ans;
    return 0;
}
/*
5 3
3 2 3 1 1

1

10 3
14 24 14 22 44 29 33 45 36 48 

8

*/
#美团笔试##美团##笔经#
全部评论
1 回复 分享
发布于 2021-09-04 18:11
这就是大佬吗  
1 回复 分享
发布于 2021-09-04 18:02
请问你是后台还是算法岗 笔试只有编程题吗
点赞 回复 分享
发布于 2021-09-24 22:34
第三题这么简单吗?ac了吗?
点赞 回复 分享
发布于 2021-09-06 22:30
大佬你不是985-211竟然有这么强的实力,是自学的吗
点赞 回复 分享
发布于 2021-09-05 11:15
第3题逆序对
点赞 回复 分享
发布于 2021-09-05 10:21
妈耶美团笔试怎么这么难了
点赞 回复 分享
发布于 2021-09-04 21:14
请问你是搞ACM的么
点赞 回复 分享
发布于 2021-09-04 19:09
你这也太强了吧
点赞 回复 分享
发布于 2021-09-04 19:08
大佬真强
点赞 回复 分享
发布于 2021-09-04 18:20
第一题斐波那契就过了
点赞 回复 分享
发布于 2021-09-04 18:20
好家伙,第二题我写bfs写晕了
点赞 回复 分享
发布于 2021-09-04 18:07

相关推荐

已经入职字节快一个月了,突然想起来之前那段时间的面经没有发,先发一下timeline吧。Tiktok&nbsp;内容安全平台(人才库电话捞我):电话10.28&nbsp;-&gt;&nbsp;一面10.30(我觉得你跟我们组业务挺match的,然后过了三天问hr挂了,应该是别人流程更快)阿里淘天:投递11.11-&gt;约面11.12-&gt;一面11.14(问得很简单,30分钟,手撕八股全过无后续)Kpi面腾讯wxg&nbsp;微信小程序:投递11.13&nbsp;-&gt;约面11.14-&gt;&nbsp;一面11.17&nbsp;(究极无敌拷打,问我多模态大模型涉及的算法?但是人很好)-&gt;11.19流程终止小红书&nbsp;风控平台:投递11.16&nbsp;—约面11.17&nbsp;&nbsp;-&gt;一面11.18&nbsp;(抽象的面试官,面试感觉一般,问得前端网页安全相关的,确实没准备)-&gt;11.20挂百度&nbsp;百家号:投递11.14&nbsp;—&gt;约面11.14&nbsp;-&gt;一面11.14(当场约2面)-&gt;二面11.24-&gt;口头告知offer,&nbsp;拒绝(原因是业务不太好)美团&nbsp;技术平台投递11.17&nbsp;-&gt;&nbsp;约面(忘记了,没多久)&nbsp;-&gt;一面11.19&nbsp;-&gt;二面11.21&nbsp;(字节offer不想面了)快手&nbsp;电商业务投递11.17&nbsp;-&gt;&nbsp;约面11.18&nbsp;-&gt;一面11.19&nbsp;-&gt;&nbsp;二面11.21(拒了)腾讯wxg&nbsp;微信支付(被捞):(直接发面试邮件)技术一面12.05&nbsp;-&gt;技术二面12.11&nbsp;-&gt;技术三面12.17&nbsp;-&gt;&nbsp;hr面已拒绝(了解业务后拒绝,但是有转正hc,感觉还蛮可惜)字节跳动&nbsp;xxxx:东家就不放具体的时间线了,大概是面完第二天就能知道结果,除了有几天ld请假了没填面评。不去wxg还有个原因是还在期末周,深圳学校来回太麻烦了,至少现在在的组感觉能学到很多的东西,自己的选择应该也没错。还是感概一下,一年前大二的时候投简历海投基本上石沉大海,无论大小厂约面比例很少。现在基本上投了就有面试,还都是以前梦寐以求的大厂,现在自己也有了更多的选择,也没有投太多简历。也感谢上一段实习的经历,很有意思的项目,无论是字节,腾讯,还是美团基本都有聊这个项目。面经需要等一下,也许等周末有空了再发给各位uu,感兴趣可以关注一下~有想要交流学习的同学也可以私信我,目前人在北京大钟寺~,可以找搭子~
正能量的牛可乐:这么多大厂面试下来,不仅摸清了不同公司的面试风格,还能精准避雷业务不匹配的岗位,血赚
实习简历求拷打
点赞 评论 收藏
分享
评论
11
32
分享

创作者周榜

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