[今日头条] 2017客户端工程师实习生笔试题
2016-09-05 12:12
627 查看
华电北风吹
天津大学认知计算与应用重点实验室
日期:2016-09-05
题目一:
很简单,按照题目要求做即可AC.
题目二:
也很简单,主要考察点是情况分类,只要细心吧所有的情况都考虑到就能AC.
题目三:
按照题目要求来即可。中间利用KMP降低时间复杂度就能AC.
题目四:
很有技巧性,把题目转化为位运算和二进制运算就容易AC了。
天津大学认知计算与应用重点实验室
日期:2016-09-05
题目一:
很简单,按照题目要求做即可AC.
#include <iostream> #include <string> using namespace std; int main() { string str; cin >> str; int N; cin >> N; int p, l; while (N--) { cin >> p >> l; string in = ""; for (int j = p + l - 1; j >= p; j--) { in += str[j]; } str = str.insert(p + l, in.c_str()); } cout << str << endl; return 0; }
题目二:
也很简单,主要考察点是情况分类,只要细心吧所有的情况都考虑到就能AC.
#include <iostream> #include <math.h> using namespace std; int main() { int n, s, L; cin >> n >> s >> L; int k = (L + 1) / (s + 1); if (k % 13 == 0) k--; int last = n%k; if (last == 0) cout << ceil(1.0*n / k) << endl; else if (last % 13 != 0) cout << ceil(1.0*n / k) << endl; else if (n / k == 0) cout << ceil(1.0*n / k) + 1 << endl; else if (k == last + 1) cout << ceil(1.0*n / k) + 1 << endl; else cout << ceil(1.0*n / k) << endl; return 0; }
题目三:
按照题目要求来即可。中间利用KMP降低时间复杂度就能AC.
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; vector<int> nextVector(const string& pattern) { int m = pattern.size(); vector<int> result(m); for (int i = 1; i < m; i++) { int j = result[i - 1]; while (j&&pattern[i] != pattern[j]) j = result[j - 1]; result[i] = pattern[i] == pattern[j] ? j + 1 : 0; } return result; } int KMP(const string& str, const string& pattern) { int n = str.size(), m = pattern.size(); vector<int> arr = nextVector(pattern); int count = 0; int p = 0; for (int i = 0; i < n; i++) { while (p>0 && pattern[p] != str[i]) p = arr[p - 1]; if (str[i] == pattern[p]) p++; if (p == m) count++; } return count; } int main() { int n, k; cin >> n >> k; vector<string> data(n); vector<int> permut(n); for (int i = 0; i < n; i++) { cin >> data[i]; permut[i] = i; } int count = 0; do { string pattern = ""; for (int i = 0; i < n; i++) { pattern += data[permut[i]]; } string str = pattern + pattern; if (KMP(str, pattern) == k + 1) { count++; } } while (next_permutation(permut.begin(), permut.end())); cout << count << endl; return 0; }
题目四:
很有技巧性,把题目转化为位运算和二进制运算就容易AC了。
#include <iostream> #include <vector> using namespace std; int main() { long long x, k; cin >> x >> k; vector<long long> bit; long long flag = 1; for (int i = 1; i < 64; i++) { if ((x&flag) == 0) bit.push_back(flag); flag = flag << 1; } flag = 1; long long y = 0; for (int i = 1; i < 64; i++) { if ((k&flag) > 0) y += bit[i - 1]; flag = flag << 1; } cout << y << endl; return 0; }
相关文章推荐
- 【牛客网】今日头条2017客户端工程师实习生笔试题
- 今日头条2017客户端工程师实习生笔试题(回文解码)
- 今日头条2017客户端工程师实习生笔试题
- 算法面试题-今日头条2017客户端工程师实习生笔试题4:或与加
- 今日头条2017后端工程师实习生笔试题——最大映射
- 今日头条2017后端工程师实习生笔试题
- 木棒拼图(multiset 的应用)----今日头条2017后端工程师实习生笔试题
- 今日头条2017后端工程师实习生笔试题
- 今日头条2017后端工程师实习生笔试题
- 今日头条2017暑期实习生招聘笔试编程题之函数最宽尖峰
- 2017今日头条前端实习生笔试题
- 今日头条2017后端工程师笔试题
- 今日头条2017实习生笔试题解
- 今日头条2017春招笔试题——所有查询句子中与给定段落单词匹配量最多的句子
- 2017今日头条前端工程师-找出函数最宽尖峰(70)
- 2017今日头条前端工程师-数列(30)
- 今日头条2017校园招聘 春招4.18笔试
- 2017实习生今日头条前端面经
- 【今日头条2017内推笔试题】二维平面整数点集
- 今日头条研发算法岗实习生笔试题解答篇_0324晚