饿了么暑期实习笔试

十道单选+七道多选 都中规中矩
第一道算法 替换字符串中的字符,用Stringbuilder拼接即可。
第二道算法,求符合要求的排列方式,又是全排列问题,应该写的没问题,但为什么只a出来5%😖
第三道算法,大数字,就是什么相加,相除再求和,我用了BigInteger,为什么只a出来7%。
全部评论
您好。请问什么岗位呀
点赞 回复 分享
发布于 04-16 13:37 江苏
笔试挂了
点赞 回复 分享
发布于 03-27 12:32 安徽
不是 你看那个114514的输入 正常方法铁超时
点赞 回复 分享
发布于 03-14 22:00 江苏

相关推荐

第一题: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个岗位
点赞 评论 收藏
分享
08-15 15:27
已编辑
门头沟学院 Java
昨晚下大雨,主包十一点多从公司往家里赶,把平板淋坏了,郁闷。--- --- --- --- ---聊实习。面试官非常有礼貌。一听是golang,对为什么投java表达了奇怪,遂不细问。常规八股:1. 抽象类与接口的区别2. JDK中你知道哪些并发安全容器3. 如果要实现一个单生产者多消费者模式,你有哪些方法?4. synchronized和reentrantlock锁之间有什么区别?5. Spring Controller如果想打印日志,怎么做?6. 如果一个Controller是上传文件的接口,那么在AOP层做完了文件流的读取,在Controller层还能重复读取吗?7. Java线上CPU打满,如何排查?8. 进程和线程的区别?9. 如何快速找到指定目录下大于100MB的所有文件10. Spring、Spring Boot中你常用的注解有哪些?11. @Autowired和@Resource之间有什么区别?12. MySQL用的是B树还是B+树,这二者有什么区别?13. delete * from,drop,truncate之间有什么区别?14. 脏读、可重复读、幻读分别说一下15. Redis常见数据结构16. Redis的Hash使用的时候有哪些注意事项?17. 给一张表,user_id, class_id, grade,找到每个班级排名第二的成绩18. 有没有用过窗口函数19. JVM类加载机制说一下聊实习情况。无手撕凉凉。体会:SSM完全生疏还没复习,大失败!非常感谢面试官帮我找状态。
我的秋招“寄”录
点赞 评论 收藏
分享
0816 京东笔试答案第一题, 减少逆序对数量对于每个 ai, 找到 所有 aj = a[i] + 1 且 j < i 的 j, 则对于选择 j < L <= i 的 L 贡献 +1, 然后做一个前缀和取最大值即可代码```#include <iostream>#include <cstring>#include <algorithm>#include <vector>#include <unordered_map>using namespace std;void solve(){int n; cin >> n;vector<int> a(n + 10, 0), b(n + 10, 0), c(n + 10, 0);unordered_map<int, vector<int>> pos;for (int i = 1; i <= n; i ++){cin >> a[i];}for (int i = 1; i <= n; i ++){int v =a[i];int t = v + 1;if (pos.find(t) != pos.end()){for (int j : pos[t]){if (j < i){b[j + 1] ++;b[i + 1] --;}}}pos[v].push_back(i);}int ans = 0;int tmp = 0;for (int i = 1; i <= n; i ++){tmp += b[i];ans = max(ans, tmp);}cout << ans << endl;}int main(){int _ = 1;cin >> _;while (_ --){solve();}}```第二题, 跳水打分解法类似求区间最值, 维护每个长度为 m 的区间的最大值和最小值, 然后遍历过去即可算出答案。代码```#include <bits/stdc++.h>#define PII pair<long, long>#define x first#define y secondusing namespace std;int main(){int n, m;cin >> n >> m;priority_queue<PII> maxPq;priority_queue<PII, vector<PII>, greater<PII>> minPq;vector<long long> a(n + 10);double ans = 0;long long tmp = 0;for (int i = 1; i <= n; i ++) cin >> a[i];for (int i = 1; i <= m; i ++){maxPq.push({a[i], i});minPq.push({a[i], i});tmp += a[i];}long long minV = minPq.top().x;long long maxV = maxPq.top().x;ans = double(tmp - minV - maxV) / (m - 2);int ans2 = 1;int l = 1, r = m;while (r < n){// cout << ans << endl;tmp -= a[l]; l ++;r ++; tmp += a[r];minPq.push({a[l], l}); minPq.push({a[r], r});maxPq.push({a[l], l}); maxPq.push({a[r], r});while (minPq.top().y < l) minPq.pop();while (maxPq.top().y < l) maxPq.pop();if ((double(tmp - minPq.top().x - maxPq.top().x) / (m - 2)) > ans){ans = double(tmp - minPq.top().x - maxPq.top().x) / (m - 2);ans2 = l;}}cout << ans2 << endl;}```
投递京东等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

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