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;
}
#美团笔试#