zoukankan      html  css  js  c++  java
  • hdu 5360 Hiking

    #include<stdio.h>
    #include<string.h>
    #include<queue>
    #include<algorithm>
    using namespace std;
    const int N=100000+5;
    
    struct node
    {
        int st,ed,id;
        friend bool operator < (node n1,node n2)
        {
            return n2.ed<n1.ed;
        }
    }p[N];
    
    priority_queue<node>q;
    bool cmp(node x,node y)
    {
        return x.st<y.st;
    }
    
    int main()
    {
        int _,n,i,j,cnt,use[N],go[N],f;
        scanf("%d",&_);
        while(_--)
        {
            scanf("%d",&n);
            memset(use,0,sizeof(use));
            f=1;
            for(i=0;i<n;i++) 
                scanf("%d",&p[i].st);
            for(i=0;i<n;i++)
            {
                scanf("%d",&p[i].ed);
                p[i].id=i+1;
            }
            sort(p,p+n,cmp);
            while(!q.empty()) q.pop();
    
            for(i=0,j=0,cnt=0;i<n;i++)
            {
                while(j<n&&p[j].st==i)
                    q.push(p[j++]);
                while(!q.empty()&&q.top().ed<i)
                {
                    q.pop();
                }
                if(q.empty()) break;
                go[cnt++]=q.top().id;
                q.pop();
            }
    
            printf("%d
    ",cnt);
            for(i=0;i<cnt;i++)
            {
                use[go[i]]=1;
                if(f==1) {printf("%d",go[i]);f=0;}
                  else printf(" %d",go[i]);
            }
    
            for(i=1;i<=n;i++)
            {
              if(use[i]==0)
              {
                  if(f==1) {printf("%d",i);f=0;}
                  else printf(" %d",i);
              }
            }
    
            printf("
    ");
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    Java 传递参数时,传递一个变量快还是传递一个实体类?
    13 设计模式
    12 反射
    11.多线程&&并发
    10.输入输出
    9.异常Exception
    7.正则表达式
    5.数组
    6.常见对象
    上传本地项目到Github
  • 原文地址:https://www.cnblogs.com/xryz/p/4847858.html
Copyright © 2011-2022 走看看