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 |
求解为什么TLE(排序贪心+堆)#include<cstdio> #include<queue> #include<algorithm> #include<cstring> using namespace std; struct product { int p,d; }a[10010],p1,p2; struct cmp_queue { bool operator()(const product & a,const product & b) { return a.p>b.p; } }; bool cmp_array(const product & a,const product & b) { return a.d<b.d; } priority_queue<product,vector<product>,cmp_queue> q; int main() { int i,j,k,m,n,x,y,z,t; while (scanf("%d",&n)) { memset(a,0,sizeof(a)); for (i=1;i<=n;i++) scanf("%d%d",&a[i].p,&a[i].d); sort(a+1,a+n+1,cmp_array); for (i=1;i<=n;i++) { if (q.size()<a[i].d) q.push(a[i]); else if (a[i].p>q.top().p) { q.pop(); q.push(a[i]); } } t=0; while (!q.empty()) { p1=q.top(); q.pop(); t+=p1.p; } printf("%d\n",t); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator