Codeforces Round #103 (Div. 2) E题

开始哥没排序还让我过了那么多数据真是奇迹了。。。。codeforces的题目不难,比的就是编码能力,代码还是要多敲~!!!
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<string>
using namespace std;
const int maxn=100111;
struct zz
{
    int l,r;
    int id;
    bool operator < ( const zz& cmp ) const
    {   
        return l < cmp.l;
    } 
}zx;
struct z2
{   
    int l;
    int r;
    int id;
    bool operator < (const z2& cmp ) const  
    {
        return r > cmp.r;
    }   
}t2;
vector<zz>v;
priority_queue<z2>q;
int a[maxn];
int n,m;
int x,y,temp,num,now,sum;
int main()
{   
    while(cin>>n>>m)    
    {     
        v.clear();
        sum=0;
        for(int i=0;i<=n;i++)
        {
            a[i]=0;
        }                                  
        while(!q.empty())
        {
            q.pop();
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&x,&y);
            zx.l=n-y+1;
            zx.r=x;
            zx.id=i;
            v.push_back(zx);
        }    
        sort(v.begin(),v.end());
        num=0;
        for(now=1 ; now <=n ; now++ )
        {
            for(;num<v.size(); )
            {   
                if(v[num].l <= now ) 
                {
                    t2.l = v[num].l;
                    t2.r = v[num].r;
                    t2.id =v[num].id;
                    q.push (t2);
                    num++;                  
                }   
                else
                {
                    break;
                }
            }
            while(!q.empty())
            {
                
                if(q.top().r < now )
                {
                    q.pop();
                    continue;
                }
                else
                {   
                    a[now]=q.top().id;
                    q.pop();
                    sum++;
                    break;
                }             
            }
        }
        cout<<sum<<endl;        
        temp=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i])
            {
                if(temp)
                {
                    printf(" ");
                }
                printf("%d",a[i]);
                temp=1;
            }
        }
        cout<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值