【百度笔试】
【本小菜鸡三道题,100,60,没做】
1、买饮料
#include <bits/stdc .h> using namespace std; int main() { // N 员工人数 // K 果汁种类数 int N, K; while (cin >> N >> K) { // A[i] b表示第 i 号员工喜欢的果汁种类 vector<int> A(N, 0); for (int i = 0; i < N; i ) { cin >> A[i]; } // 统计次数 vector<int> count(K 1, 0); for (int i = 0; i < N; i ) { count[A[i]] ; } int global = 0; for (int i = 1; i <= K; i ) { global = count[i] / 2; global = count[i] % 2; } cout << global << endl; } return 0; }
2、发工资
#include <bits/stdc .h> using namespace std; int main() { // N 种面额 // M 最少工资 int N, M; while (cin >> N >> M) { vector<pair<int, int>> V; for (int i = 0; i < N; i ) { int X, Y; cin >> X; cin >> Y; V.push_back(make_pair(X, Y)); } int global = 0; sort(V.begin(), V.end()); for (int i = 0; i < N; i ) { if (V[i].first > M) { global = V[i].second; } else { if (V[i].first * V[i].second >= M) { int tmp = 0; int count = 0; while (V[i].second--) { tmp = V[i].first; count ; if (tmp >= M) { global = 1; // 这里有问题,AC 60% } } } else { global = 0; } } } cout << global << endl; } return 0; }