首页
题库
公司真题
专项练习
面试题库
在线编程
面试
面试经验
AI 模拟面试
简历
求职
学习
课程
专栏·文章
竞赛
搜索
我要招人
发布职位
发布职位、邀约牛人
更多企业解决方案
在线笔面试、雇主品牌宣传
登录
/
注册
virtual_system
菜鸟网络_物流科技部_研发工程师
获赞
75
粉丝
1
关注
1
看过 TA
30
男
电子科技大学
2020
Java
IP属地:浙江
暂未填写个人简介
私信
关注
拉黑
举报
举报
确定要拉黑virtual_system吗?
发布(20)
刷题
virtual_system
2021-06-16 10:25
菜鸟网络_物流科技部_研发工程师
题解 | #查找组成一个偶数最接近的两个素数# 先筛素数,再从中间向两边查找
优化1 我们可以预处理出来一个小于n的素数数组,而不必每次去判断是否为素数。 优化2 从素数数组中间向两边查找,时间一定是最短的 #include <bits/stdc++.h> using namespace std; constexpr int N = 1010; bool st[N]; inline void solve(int &n) { vector<int> pr; for (int i = 2; i <= n; i++) { if (!st[i]) { pr.push_back(i...
0
点赞
评论
收藏
转发
virtual_system
2021-08-15 16:40
已编辑
菜鸟网络_物流科技部_研发工程师
题解 | #质数因子#埃氏筛+最大质因子性质
从i = 2开始遍历的时候,使用如下两个方法对代码进行优化: 一个正整数的质因子,最多只有一个大于其平方根。 证明:假设有超过一个质因子大于其平方根,那么二者相乘一定大于该数。得证。 如果找到一个质因子,那么该质因子的2倍、3倍...都不是质因子。 #include <bits stdc++.h> using namespace std; //constexpr long long N = 1e10 + 10; //bool st[N]; unordered_map<long, bool> st; inline void solve(long &amp;n...
0
点赞
评论
收藏
转发
virtual_system
2021-06-12 15:44
菜鸟网络_物流科技部_研发工程师
题解 | #人民币转换# 前后缀分治,递归处理
思想 对于给定字符串,按照 亿、万、仟、佰、拾 依次根据字符串长度找到最高级别单位划分前后缀,递归处理。 举例 12031,0200,3002我们先考虑没有小数的情况(小数很简单最后处理)。len = 13 ,13 - 1对8整除商大于0,所以最高位是亿。那么答案必然是 xxx亿xxx.(减1是因为我们只判断最高位后面的字符串长度)此时我们对原字符串划分前后缀,依次递归判断:prefix = 12031suffix = 02003002前后缀最高级别单位是万. 细节处理 零的处理当某一段全为零时,如50000,前缀5 + 单位万 + 后缀0000. 后缀全为0,我们直接全部略过。当某一段的前...
0
点赞
评论
收藏
转发
virtual_system
2021-06-12 00:01
菜鸟网络_物流科技部_研发工程师
题解 | #求解立方根# 浮点数二分法
注意数字 a 如果在[0, 1],那么它的立方根是比它大的,右边界取到 a 是不够的,负数同理。 #include <bits/stdc++.h> using namespace std; void solve(double &a) { double lo = a < 0 ? min(a, -1.0) : 0.0; double hi = a > 0 ? max(a, 1.0) : 0.0; for (int i = 0; i < 1000; i++) { double mid = (double)(lo + ...
0
点赞
评论
收藏
转发
virtual_system
2021-06-10 23:50
菜鸟网络_物流科技部_研发工程师
题解 | #在字符串中找出连续最长的数字串# 计数排序思想求最大值
the code says it all: #include <bits/stdc++.h> using namespace std; const int N = 1010; string cnt[N]; void solve(string s) { s += '*'; string t = ""; int mxlen = -1; for (int i =0; i < s.size(); i++) { char c = s[i]; if (isdigit(c)) { ...
0
点赞
评论
收藏
转发
virtual_system
2021-06-09 21:33
菜鸟网络_物流科技部_研发工程师
题解 | #MP3光标位置# 模拟窗口和光标移动
注意边界情况。 #include<bits/stdc++.h> using namespace std; const int N = 1e4 + 10; int music[N]; int m; int hh, tt, idx; inline void move2(char c) { if (c == 'U') { if (idx > 1) idx--; else idx = m; } else if (c == 'D') { if (idx <...
0
点赞
评论
收藏
转发
virtual_system
2021-06-09 10:21
已编辑
菜鸟网络_物流科技部_研发工程师
题解 | #查找输入整数二进制中1的个数# lowbit得到二进制最低位1
lowbit原理 这里最后一位1是指从左往右最后一位,函数lowbit()返回的是包含该1与右边所有0。 int lowbit(int x) { return x & - x; } -x 在计算机内部是以补码方式运算的,即:-x = ~ x + 1假设一个二进制数为: 0010101…0010100000~x 为: 1101010…1101011111~x + 1 为: 1101010…1101100000注意到+1操作使得最后一位1及其右边所有数字发生了变化,而左边不变。此时在和原数字进行&运算,它和原数字在最后一位1左侧全部不同,右侧全部相同。 code #incl...
0
点赞
评论
收藏
转发
virtual_system
2021-06-09 10:13
已编辑
菜鸟网络_物流科技部_研发工程师
题解 | #找出字符串中第一个只出现一次的字符# 计数数组统计出现次数
注意题目并没有限制字符串中所有字符均为字母,所以要考虑到所有字符的情况。 #include<bits/stdc++.h> using namespace std; const int N =1010; int cnt[N]; int main() { string s; for (; cin >> s; memset(cnt, 0, sizeof(cnt))) { for (const auto &c : s) cnt[c]++; bool is_found = false; ...
0
点赞
评论
收藏
转发
virtual_system
2021-06-09 09:43
菜鸟网络_物流科技部_研发工程师
题解 | #输入n个整数,输出其中最小的k个#TopK c++ 最大堆实现
使用堆得自动排序功能,维护一个大小为k的最大堆。最终输出k个数即为最小k个数。如果是求最大k个数,那么就使用最小堆。 #include<bits/stdc++.h> using namespace std; int main() { int m, k; for (; cin >> m >> k;) { vector<int> nums; for (; m--;) { int x; cin >> x; nums.p...
0
点赞
评论
收藏
转发
virtual_system
2021-06-09 08:50
菜鸟网络_物流科技部_研发工程师
题解 | #高精度整数加法# c++模拟加法过程
字符串逆序方向模拟加法过程,注意处理边界进位。 #include<bits/stdc++.h> using namespace std; typedef long long LL; inline int ctoi(char c) { return c - '0'; } void add(string &s1, string &s2) { if (s1.size() > s2.size()) return add(s2, s1); vector<int> vec; int tt = 0; for (i...
0
点赞
评论
收藏
转发
virtual_system
2021-06-07 17:47
已编辑
菜鸟网络_物流科技部_研发工程师
题解 | #蛇形矩阵# 模拟矩阵构造过程
维护行指针 r 和列指针 c,移动两个指针构造整个矩阵。蛇形矩阵满足条件: 第一个格子始终是1; 当 r 为 0 时,下一位 r 为当前 c + 1; 下一位 c 为 0; 如果 r 和 c 不满足条件2,那么下一位 r 为 当前 r - 1,下一位 c 为 当前 c + 1; #include<bits/stdc++.h> using namespace std; int main() { int n; for (; cin >> n;) { vector<vector<int>> grid; ...
0
点赞
评论
收藏
转发
virtual_system
2021-06-07 15:40
菜鸟网络_物流科技部_研发工程师
题解 | #密码验证合格程序#
可以使用位运算记录字符种类 判断是否含有重复子串的时候,只需要判断长度为3的子串即可。 #include<bits/stdc++.h> using namespace std; inline bool SubStringDetermine(string s) { unordered_map<string, int> hash; // i : length of sub string //for (int len = 3; len < s.size() - 1; len++) int len = 3; { ...
0
点赞
评论
收藏
转发
virtual_system
2021-06-06 16:49
菜鸟网络_物流科技部_研发工程师
题解 | #字符串加密#
此题考查十进制和二进制的转换。 #include <bits/stdc++.h> using namespace std; typedef long long LL; inline LL DecStringToDec(string s) { // to int LL dec = 0; for&...
0
点赞
评论
收藏
转发
virtual_system
2021-06-02 00:39
菜鸟网络_物流科技部_研发工程师
题解 | #输出单向链表中倒数第k个结点#
考察单链表的构造与遍历。 递归 #include <bits/stdc++.h> struct ListNode { int m_nKey; ListNode* m_pNext; ListNode(int x) : m_nKey(x), m_pNext(nullptr) {} }; using namespace std; int k; int cnt; vector<int> nums; ListNode* res; void dfs2(ListNode* node) { if (node == nullptr) ...
0
点赞
评论
收藏
转发
virtual_system
2021-06-01 21:15
已编辑
菜鸟网络_物流科技部_研发工程师
题解 | #从单向链表中删除指定值的节点#
链表+字符串,首先将字符串处理成一个数组,再模拟构造链表,按照操作进行增加和删除节点操作。 #include <bits/stdc++.h> using namespace std; const int N = 10000010; int idx, head, n[N], ne[N]; vector<int> nums; unordered_map<int, int> _map; // value - idx int new_value, old_value; inline int ctoi(char c) { return c -...
0
点赞
评论
收藏
转发
1
2
工具箱
TA的圈子
暂未加入圈子
TA的圈子
TA的笔记
暂无笔记
TA的笔记
登录
0
天
已登录
0
天
连续登录
0
人
今日访客
牛客网
牛客企业服务