美团笔试8.13嵌入式

100 100 100 82
1、魔法送外卖
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
  int n, t;
  cin >> n;
  cin >> t;
  vector<int> a(n);
  for(int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a.begin(), a.end());
  int c = t;
  int ans = 0;
  for(int j = 0; j < n; ++j) {
    if(a[j] - c >= 0)
      c += t;
    else
      ++ans;
  }
  cout << ans;
}
2、扫地机器人扫地
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  int n, m, k;
  cin >> n;
  cin >> m;
  cin >> k;
  string ins;
  cin >> ins;
  vector<vector<bool>> space(n, vector<bool>(m, false));
  space[0][0] = true;
  int amount = 1;
  int x = 0, y = 0;
  for(int i = 0; i < k; ++i) {
    if(ins[i] == 'W') {
      if(x - 1 >= 0) {
        x = x - 1;
        if(!space[x][y]) {
          space[x][y] = true;
          ++amount;
        }
      }
      if(amount == n * m) {
        cout << "Yes" << endl;
        cout << i + 1;
        return 0;
      }
    }
    else if(ins[i] == 'A') {
      if(y - 1 >= 0) {
        y = y - 1;
        if(!space[x][y]) {
          space[x][y] = true;
          ++amount;
        }
      }
      if(amount == n * m) {
        cout << "Yes" << endl;
        cout << i + 1;
        return 0;
      }
    }
    else if(ins[i] == 'S') {
      if(x + 1 < n) {
        x = x + 1;
        if(!space[x][y]) {
          space[x][y] = true;
          ++amount;
        }
      }
      if(amount == n * m) {
        cout << "Yes" << endl;
        cout << i + 1;
        return 0;
      }
    }
    else if(ins[i] == 'D') {
      if(y + 1 < m) {
        y = y + 1;
        if(!space[x][y]) {
          space[x][y] = true;
          ++amount;
        }
      }
      if(amount == n * m) {
        cout << "Yes" << endl;
        cout << i + 1;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  cout << n * m - amount;
  
  return 0;
}
3、扑克牌复原
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;

int main() {
  int n;
  cin >> n;
  queue<int> a;
  vector<int> pos;
  int ans[n];
  for(int i = 0; i < n; ++i)
    a.push(i);
  while(!a.empty()) {
    a.push(a.front());
    a.pop();
    a.push(a.front());
    a.pop();
    pos.push_back(a.front());
    a.pop();
  }
  for(int i = 0; i < n; ++i)
    cin >> ans[pos[i]];
  cout << ans[0];
  for(int i = 1; i < n; ++i)
    cout << ' ' << ans[i];
  
  return 0;
}
4、三元组
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  int ans = 0;
  for(int i = 0; i < n; ++i)
    cin >> a[i];
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      for(int k = j + 1; k < n; ++k) {
        if(a[i] - a[j] == 2 * a[j] - a[k])
          ++ans;
      }
    }
  }
  cout << ans;
}

#美团笔试#
全部评论
都是手撕代码吗
点赞 回复 分享
发布于 2022-08-15 18:21

相关推荐

07-22 13:50
门头沟学院 Java
仁者伍敌:其实能找到就很好了,当然收支能抵
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
3
15
分享

创作者周榜

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