饿了么秋招8.15工程卷笔试

考试是测评和笔试两个合在一起,选择题有部分行测,考了数据库,还有设计模式等。

算法第一题,给出一个数字n,输出m个数字,要满足符合以下要求:a1 xor a2 xor a3 xor...xor an = a1 or a2 or a3 or ... or an。

例如给出一个数字4,可以输出的结果有5 6 4 8,答案不限,只要满足以上要求就行

5->0101
6->0110
4->0100
8->1000

0101 xor 0110 xor 0100 xor 1000 = 15
0101 or 0110 or 0100 or 1000 = 15

第二题,是有m个木棍,每根木棍的长度是n,问这些木棍可以拼出多少个正多边形?(答案较大,要取模)

比如说有8根木棍,每根木棍的长度分别是1,1,1,3,2,2,2,2

然后输出m-2个结果,分别代表正三边形,正四边形,正五边形等可以组成多少个,答案是5,1,0,0,0,0

要求说只要不重合和不折断就行

第三题是图论,直接略😅

鼠鼠一个凑安全的,尽力了……

#饿了么# #秋招笔面试记录#
全部评论
三道算法,第一题死活不对,写了两遍,第二题a了,第三个超时 大概率是挂了
1 回复 分享
发布于 08-15 23:32 黑龙江
你好 我第一次做这种笔试 这种算法题要写代码还是要写思路
点赞 回复 分享
发布于 昨天 12:26 上海

相关推荐

第一题:n为奇数输出n个1,n为偶数输出n-1个0即可:#include <iostream>using namespace std;int main() {int t;cin >> t;while (t --) {int n;cin >> n;if (n & 1) {for (int i = 0; i < n; i ++) {cout << 1 << " ";}cout << '\n';} else {for (int i = 0; i < n - 1; i ++) {cout << 1 << " ";}cout << 0 << '\n';}}}第二题:如果你有n个长度相同的木棍,那么他们组成正m边形的组合是C(n,m)个,C是组合数,计下数就可以了。#include <bits/stdc++.h>using namespace std;#define int long longconst int p = 998244353;const int N = 5e3 + 10;int h[N], rh[N];int C(int n, int m) {if (n < m) return 0;return h[n] * rh[m] % p * rh[n - m] % p;}int qs(int a, int b) {int res = 1;while (b) {if (b & 1) res = res * a % p;a = a * a % p;b >>= 1;}return res;}signed main() {h[0] = rh[0] = 1;for (int i = 1; i < N ; i ++) {h[i] = h[i - 1] * i % p;rh[i] = qs(h[i], p - 2);}int n;cin >> n;map<int, int> mp;for (int i = 0; i < n; i ++) {int x;cin >> x;mp[x] ++;}for (int i = 3; i <= n; i ++) {int res = 0;for (auto& it : mp) {res = (res + C(it.second, i)) % p;}cout << res << ' ';}}3,最小生成树模板题,注意处理一下正边#include <cmath># include <iostream>#include <queue>using namespace std;const int N = 1e5 + 10;int p[N];int find(int x) {if (x != p[x]) p[x] = find(p[x]);return p[x];}int main() {int n, m;cin >> n >> m;priority_queue<pair<int, pair<int, int>>> pq;for (int i = 1; i <= n; i ++) p[i] = i;for (int i = 1 ; i <= m; i ++) {int u, v, x;cin >> u >> v >> x;pq.push({x, {u, v}});}long long res = 0;while (pq.size() > 0) {auto t = pq.top();pq.pop();int u = t.second.first;int v = t.second.second;int x = t.first;if (x >= 0) {res += x;p[find(u)] = find(v);} else if (find(u) != find(v)) {res += x;p[find(u)] = find(v);}}cout << res << '\n';
投递饿了么等公司10个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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