//大佬是这么写的,为啥一直0%,自己测试用例和想的用例都能过 #include <iostream> #include<algorithm> #include<vector> #include<math.h> using namespace std; int main() {     int n, m, temp;     cin >> n >> m;     vector<int> vea, veb, vetemp;     int total_a = 0, total_b = 0;     for (int i = 0; i<n; i++) {         cin >> temp;         vea.push_back(temp);         total_a += temp;     }     for (int i = 0; i<m; i++) {         cin >> temp;         veb.push_back(temp);         total_b += temp;     }     int res = 0;     double avg_a = (double)total_a / n, avg_b = (double)total_b / m;     if (avg_a>avg_b) {         vetemp = vea; vea = veb; veb = vetemp;         temp = n; n = m; m = temp;         temp = total_a; total_a = total_b; total_b = temp;     }     sort(veb.begin(), veb.end());     while (1) {         if (m == 1) break;         avg_a = (double)total_a / n;         avg_b = (double)total_b / m;         if (avg_a >= avg_b) break;         int tip1 = lower_bound(veb.begin(), veb.end(), avg_a) - veb.begin();         int tip2 = lower_bound(veb.begin(), veb.end(), avg_b) - veb.begin();         if (tip1<tip2) {             res++;             total_a += veb[tip1];             total_b -= veb[tip1];             n++;             m--;             veb.erase(veb.begin() + tip1);         }         else break;     }     cout << res << endl;     system("pause");     return 0; }
点赞 评论
牛客网
牛客企业服务