Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

没想明白这代码怎么会MLE?(附代码)

Posted by Debugcool at 2010-03-27 19:45:26 on Problem 2431
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
struct po
{
    int l,p;
}a;
bool cmp(po a,po b)
{
    return a.l > b.l;
}
struct cmp1
{
    bool operator()(po a,po b)
    {
        return a.p < b.p;
    }
};
vector<po> V;
priority_queue<po,vector<po>,cmp1> q;
int main()
{
    int n,ll,pp,c,flag,j,temp;
    po k;
    while (scanf("%d",&n) == 1)
    {
        flag = c = 0;
        V.clear();
        for (int i = 0;i < n;i++)
        {
            scanf("%d %d",&a.l,&a.p);
            V.push_back(a);
        }
        scanf("%d%d",&ll,&pp);
        sort(V.begin(),V.end(),cmp);
        temp = ll;
        j = 0;
        temp -= pp;
        while (temp > 0)
        {
            if (j == n)
                break;
            if (temp > V[j].l && q.empty())
                break;
            else
            {
                for (j = 0;j < n;j++)
                {
                    if (V[j].l >= temp)
                        q.push(V[j]);
                    else
                        break;
                }
                k = q.top();
                pp = k.p;
                temp -= pp;
                q.pop();
                c++;
            }
        }
        if (temp <= 0)
            printf("%d\n",c);
        else
            printf("-1\n");
        while (!q.empty())
            q.pop();
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator