大佬们帮忙看看我今天广联达笔试第一道题有什么问题
vs上没问题 提交时编译不过
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; int main() { int n, m, x; // m 次数 x高度 cin >> n >> m >> x; if (n == 1) { cout << m * x << endl; return 0; } auto p = [](pair<int, int>a, pair<int, int>b) {return a.first > b.first; }; priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(p) > height(p); int h; while (n--) { cin >> h; height.push(make_pair(h, 0)); } int t = height.top().first; height.pop(); height.push(make_pair(t, -1)); while (m--) { int temp1 = height.top().first, temp2 = height.top().second; height.pop(); height.push(make_pair(temp1 + x, temp2)); } int res = 0; while (height.top().second == 0) { height.pop(); } res = height.top().first; cout << res << endl;; system("pause"); return 0; }
全部评论
(2) 回帖