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 |
Re:优先队列 AC +代码In Reply To:优先队列 AC +代码 Posted by:wylqq312715289 at 2013-09-24 18:56:38 > #include <iostream> > #include <cstdio> > #include <queue> > using namespace std; > struct T{ > int x; > const bool operator<(T a) const{ > return a.x<x; > } > }; > T a[20019]; > int main(){ > int n; > long long res; > priority_queue<T> q; > while(!q.empty()) q.pop(); > while(scanf("%d",&n)!=EOF){ > res = 0; > for(int i = 0;i<n;i++) { > scanf("%d",&a[i].x); > q.push(a[i]); > } > for(int i = 0;i<n-1;i++){ > T temp; > T x = q.top();q.pop(); > T y = q.top();q.pop(); > res = res + x.x + y.x; > temp.x = x.x + y.x; > q.push(temp); > } > while(!q.empty()) q.pop(); > cout<<res<<endl; > } > return 0; > } 这段代码显然是有问题的,n=1的情况都没有考虑。 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator