拼多多笔试运货那题有人做出来吗?
下面想不到哪里错了,感觉思路没问题,有大佬讲一下吗?
#include <iostream> #include <vector> #include <cmath> #include <map> #include <algorithm> using namespace std; int w[1100]; int mark[1100]; int main() { int tmp; int n = 0; int res = 0; while (cin >> tmp) { if (tmp > 200) { res++; } else { w[n] = tmp; mark[n] = 0; n++; } } sort(w, w + n); for (int i = n - 1; i >= 0; i--) { if (mark[i] == 1) { continue; } res++; mark[i] = 1; int sum = w[i]; for (int t = i - 1; t >= 0; t--) { if (mark[t] == 0 && sum + w[t] <= 300) { mark[t] = 1; sum = sum + w[t]; } } } cout << res << endl; } /* 6 190 100 100 190 190 100 9 100 110 190 100 190 110 190 110 100 */
#拼多多##笔试题目#