美团0813笔试
外卖 a100
int main() { int n = 0, t = 0; cin >> n; cin >> t; vector<int> endTimes; int end_time; int num = 0; while (num<n) { cin >> end_time; endTimes.push_back(end_time); num++; } int now_time = 0; sort(endTimes.begin(), endTimes.end()); int i = 0; int ans = 0; while (i < n) { if (now_time + t <= endTimes[i]) { now_time += t; } else { ans++; } i++; } cout << ans << endl; }
扫地机器人 a100
int main() { int m = 0, n = 0, k = 0; cin >> m >> n >> k; string command; cin >> command; vector<vector<int>> matrix(m, vector<int>(n, 0)); matrix[0][0] = 1; int left = m * n - 1; unordered_map<char, pair<int, int>> directions; directions.insert({ 'W',{-1,0} }); directions.insert({ 'S',{1,0} }); directions.insert({ 'A',{0,-1} }); directions.insert({ 'D',{0,1} }); int row = 0, col = 0; int i = 0; for (; i < k; i++) { char d = command[i]; row += directions[d].first; col += directions[d].second; if (matrix[row][col] == 0) { matrix[row][col] = 1; left--; } if (left == 0) { break; } } if (left == 0) { cout << "yes" << endl; cout << i + 1 << endl; } else { cout << "no" << endl; cout << left << endl; } return 0; }两小伙耍牌 a100
int main() { int n = 0; cin >> n; int num = 0; vector<int> nums; while (cin >> num) { nums.push_back(num); } deque<int> q; int i = n - 1; while (i >= 0) { num = nums[i]; q.push_front(num); if (q.size() > 1) { num = q.back(); q.pop_back(); q.push_front(num); num = q.back(); q.pop_back(); q.push_front(num); } i--; } cout << q[0]; for (int i = 1; i < n; i++) { cout << " " << q[i]; } cout << endl; return 0; }ijk条件符合个数 a了90
int main() { int n = 0; cin >> n; int num = 0; vector<int> nums(n,0); unordered_map<int, vector<int>> m; int index = 0; while (cin >> num) { nums[index] = num; m[num].push_back(index); index++; } int ans = 0; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { int target = 3 * nums[j] - nums[i]; if (!m.count(target)) { continue; } vector<int> indexs = m[target]; int low = 0, high = indexs.size(); while (low < high) { int mid = low + (high - low) / 2; if (indexs[mid] > j) { high = mid; } else { low = mid + 1; } } ans += (indexs.size() - high); } } cout << ans << endl; return 0; }
感觉美团的题目是大厂里相对容易些的 基本10分钟一道 就是最后一道半天都是90 不知道哪里卡住了 选的岗位的原因第五道是多选题