美团网上笔试题
前言
2018.9.6美團(tuán)的網(wǎng)上筆試題,基礎(chǔ)題目離不開計算機(jī)網(wǎng)絡(luò),操作系統(tǒng),數(shù)據(jù)結(jié)構(gòu)和數(shù)據(jù)庫。這些基礎(chǔ)學(xué)科都考了(估計大多數(shù)崗位這些題是一樣的),其他題的不同取決于應(yīng)聘的職位。筆試還出現(xiàn)了一些邏輯題和數(shù)學(xué)題。
?
這道編程題還是比較簡單的,不要想的太復(fù)雜,很快就能做出來。
#include <iostream> using namespace std;int main() {int i = 1; //i是退出循環(huán)的標(biāo)記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; elsen -= 1;j+=1; //組成3人隊伍,隊數(shù)加一}elsei=0;}cout << "SUM:" << j <<endl;return 0; } 輸入:4 輸入:530 20 50 50 13 10 21 1510 10 20 15 3 4 15 1060 80 70 83 20 13 25 1840 40 50 75 33 26 45 4060 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); }?
超強(qiáng)干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
- 上一篇: C++学习笔记:(九)输入/输出流
- 下一篇: C++学习笔记:(十)异常