In Zhejiang University, there are N different courses labeled from 1 to N. Each course has its own time slot during the week. We can represent the time slot of a course by an left-closed right-open interval [s, t).

Now we are going to arrange the final exam time of all the courses.

The final exam period will contain multiple days. In each day, multiple final exams will be held simultaneously. If two courses' time slots are not overlapped, there may be students who are attending both of them, so we cannot arrange their final exams at the same day.

Now you're to arrange the final exam period, to make the total days as small as possible.

Input

There are multiple test cases separated by blank lines.

For each ease, the 1st line contains one integer N(1<=N<=100000).

Then N lines, the i+1th line contains s and t of the interval [s, t) for the ith course.(0<=s<t<=231-1)

There is a blank line after each test case.

Output

For each case, the 1st line contains the days P in the shortest final exam period.

Next P lines, the i+1th line contains the numbers of courses whose final exam is arranged on the ith day separated by one space.

Output a blank line after each test case.

Sample Input

4
0 1
1 2
2 3
3 4 4
0 2
1 3
2 4
3 5 4
0 4
1 5
2 4
3 6

Sample Output

4
1
2
3
4 2
1 2
3 4 1
1 2 3 4
 #include <stdio.h>
#define N 100005
#include <algorithm>
using namespace std; struct node
{
int a,b,num;
} po[N];
int out[*N+];
int cmp(node x,node y)
{
if(x.a==y.a) return x.b>y.b;
return x.a<y.a;
}
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=; i<n; i++)
{
scanf("%d%d",&po[i].a,&po[i].b);
po[i].num=i;
}
sort(po,po+n,cmp);
int k,ans=,c=;
for(i=; i<n; )
{
k=po[i].b;
for(j=i; ; j++)
{
if(po[j].a>=k)
{
i=j;
ans++;
out[c++]=-;
break;
}
else
{
out[c++]=po[j].num;
if(po[j].b<k) k=po[j].b;
}
if(j==n)
{
i=n;
break;
}
}
}
printf("%d\n",ans+);
for(i=; i<c-; i++)
{
if(out[i]==-) puts("");
else
{
if(i && out[i-]!=-) putchar(' ');
printf("%d",out[i]+);
}
}
puts("\n");
}
return ;
}

贪心

Final Exam Arrangement(ZOJ)的更多相关文章

  1. zoj 3721 Final Exam Arrangement【贪心】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 来源:http://acm.hust.edu.cn/vjudg ...

  2. Java中static、final、static final的区别(转)+transient

    说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...

  3. Drools 7.4.1.Final参考手册(八) 规则语言参考

    规则语言参考 概述 Drools有一个“本地”的规则语言.这种格式在标点符号上非常轻,并且通过“扩展器”支持自然语言和领域特定的语言,使语言能够变形到您的问题领域.本章主要与本机规则格式一致.用于表示 ...

  4. Drools 7.4.1.Final参考手册(六) 用户手册

    用户手册 基础 无状态的知识Session Drools规则引擎拥有大量的用例和功能,我们要如何开始?你无须担心,这些复杂性是分层的,你可以用简单的用例来逐步入门. 无状态Session,无须使用推理 ...

  5. public,protected,private,static,final的区别(转载)

    1.类 (1)在java中有public.protected.private三种显示的修饰符用于控制可见性,package不是显示的修饰符,它是隐含的,即如果在类.变量等前没加显示的可见性修饰符,那它 ...

  6. 为什么接口要规定成员变量必须是public static final的呢?(转)

    在interface里面的变量默认都是public static final 的.所以可以直接省略修饰符: String param="ssm"://变量需要初始化 为什么接口要规 ...

  7. Java中static、final、static final的区别(转)

    说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...

  8. UVa 1638 - Pole Arrangement(dp)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. final static 修饰(转载)

    static修饰符        static修饰符能够与属性.方法和内部类一起使用,表示静态的.类中的静态变量和静态方法能够与类名一起使用,不需要创建一个类的对象来访问该类的静态成员,所以,stat ...

随机推荐

  1. Elevator(hdoj 1008)

    Problem Description The highest building in our city has only one elevator. A request list is made u ...

  2. Ubuntu配置OpenGL环境

    建立基本编译环境 sudo apt-get install build-essential 安装OpenGL Library sudo apt-get install libgl1-mesa-dev ...

  3. 什么是Activity、生命周期

    1.什么是Activity 1.当程序第一次运行时用户就会看这个Activity,这个Activity可以通过启动其他的Activity进行相关的操作. 2.当启动其他的Activty时这个当前的这个 ...

  4. U盘开发之GPIF Master模式

    在U盘开发过程中,一个人从头做到尾,经常遇到一些莫名其妙的问题,只有到官网论坛发帖.折腾困扰我最久的,就是U盘的读写性能问题了,不采用GPIF的方式,single读只有几百K,single写只有几十K ...

  5. logstash grok正则调试

    logstash 正则调试: nginx 配置: log_format main '$remote_addr [$time_local] "$request" '; logstas ...

  6. VC实现图片拖拽及动画

    基础知识 1.PictureBox控件的使用 2.加载位图文件 1.通过文件路径获得位图句柄 //获得位图句柄  void CMovePictureDlg::GetHandleFromPath(CSt ...

  7. Java 基础类型

    在Java中,基本的数据类型主要有8种: 1)int  4 字节(byte)  -2的31次方到2的31次方-1 2)short 2 字节(byte) -2的15次方到2的15次方-1 3)long ...

  8. OpenStack IdentityService Keystone V3 API Curl实战

    v3 API Examples Using Curl <Tokens> 1,Default scope 获取token Get an token with default scope (m ...

  9. Problem "g++" ("gcc") not found in PATH [ in omnet++ ] ---- 关于OMNeT++软件使用问题

    出现的问题就像下面这样: 解释一下我出现这种情况的背景: 1. 首先安装好了OMNeT++软件,关于OMNeT++软件是否安装成功详见另一篇文章 OMNeT++安装教程 2. 也安装好了GCC编译环境 ...

  10. RTNETLINK answers: Operation not permitted

    如果出现:RTNETLINK answers: Operation not permitted,那是因为没有权限. 解决办法:su,输入root密码.