Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WA到死的看这里,讲两个坑点,贴一个AC代码1.结果要用long long类型 2.不要printf("%d\n", ans);数据类型是long long和%d不匹配的,改成cout就可以 用priority_queue的代码: #include <queue> #include <vector> #include <functional> #include <iostream> using namespace std; int main(void) { int n, i; long long ans = 0; priority_queue<int, vector<int>, greater<int>> pQ; cin >> n; for(i = 0; i < n; i++){ int a; cin >> a; pQ.push(a); } while(pQ.size() >= 2){ int x, y; x = pQ.top(); pQ.pop(); y = pQ.top(); pQ.pop(); ans += (x + y); pQ.push(x + y); } cout << ans << endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator