前言
2018.9.6美团的网上笔试题,基础题目离不开计算机网络,操作系统,数据结构和数据库。这些基础学科都考了(估计大多数岗位这些题是一样的),其他题的不同取决于应聘的职位。笔试还出现了一些逻辑题和数学题。
这道编程题还是比较简单的,不要想的太复杂,很快就能做出来。
#include <iostream>
using namespace std;
int main()
{
int i = 1; //i是退出循环的标记
int j=0; //j用来记录能组多少队
int n,m; //n,m代表两类人
cout << "Input n&m:";
cin >> n >> m;
while(i == 1 && m >= 1 && n>= 1)
{
if(m+n>=3)
{
m -= 1;
n -= 1; //3人成一队,编程的人和算法的人都先选一个
if(m > n) //剩下的那一个人就从人多的里面选
m -= 1;
else
n -= 1;
j+=1; //组成3人队伍,队数加一
}
else
i=0;
}
cout << "SUM:" << j <<endl;
return 0;
}
输入:4 输入:5
30 20 50 50 13 10 21 15
10 10 20 15 3 4 15 10
60 80 70 83 20 13 25 18
40 40 50 75 33 26 45 40
60 41 78 80
输出:165 输出:112
思路:背包问题
#include <bits/stdc++.h>
using namespace std;
int TIME = 121;
int process(const vector<int>& p, const vector<int>& a, const vector<int>& q, const vector<int>& b)
{
int n = p.size();
if (n == 0) return 0;
vector<vector<int> > memo(n,vector<int>(TIME+1,-1));
for (int j = 0; j <= TIME; ++j) {
memo[0][j] = (j >= p[0] ? a[0]:0);
memo[0][j] = (j >= q[0] && b[0] > a[0] ? b[0]:memo[0][j]);
}
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= TIME ; ++j) {
memo[i][j] = memo[i-1][j];
if (j >= p[i])
memo[i][j] = max(memo[i][j],a[i] + memo[i-1][j-p[i]]);
if (j >= q[i]) {
memo[i][j] = max(memo[i][j],b[i] + memo[i-1][j-q[i]]);
}
}
}
return memo[n-1][TIME];
}
int main()
{
int n;
cin >> n;
int dp[TIME];
memset(dp, 0, TIME * sizeof(int));
int p, a, q, b;
vector<int> pVector;
vector<int> aVector;
vector<int> qVector;
vector<int> bVector;
for (int k = 0; k < n; ++k) {
cin >> p >> a >> q >> b;
pVector.push_back(p);
aVector.push_back(a);
qVector.push_back(q);
bVector.push_back(b);
}
cout << process(pVector,aVector,qVector,bVector);
}