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

小生用了map…657ms…红黑树果然效率低啊……

Posted by analysiser at 2009-08-07 13:06:43 on Problem 1089
rt...
估计如果不用scanf和printf就TLE了……想办法优化优化……
//1089
#include <iostream>
#include <map>
using namespace std;
 
int main()
{
    map<int,int> p;
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        if(p.find(l)!=p.end())
        {
            if(p.find(l)->second<r)
                p.find(l)->second=r;
        }
        else
            p.insert(pair<int,int>(l,r));
    }
    map<int,int>::iterator s=p.begin();
    map<int,int>::iterator it;
    while(s!=p.end())
    {
        int left=s->first;
        int right=s->second;
        it=++s;
        while(it->first<=right && it!=p.end())
        {
            right=(it->second>right)?it->second:right;
            it++;
        }
        printf("%d %d\n",left,right);
        s=it;
    }

    system("pause");
    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