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. 在Windows XP下手动安装Apache+MySQL+PHP环境 要点

    在整个wamp环境搭建中,本质的工作如下: 1,配置系统对php中dll文件能默认处于调用状态.在windos下,对dll文件系统默认处于调用状态的,有两种采用的方式.第一种是:把需要调用dll文件复 ...

  2. Mvc中使用MvcSiteMapProvider实现站点地图之基础篇

    MvcSiteMapProvider 是针对 ASP.NET MVC 中,提供菜单. 网站地图. 站点地图路径功能,以及更多的工具.它提供配置使用一个可插入的体系结构,可以是 XML. 数据库或动态生 ...

  3. javascript 事件设计模式

    http://plkong.iteye.com/blog/213543 1. 事件设计概述 事件机制可以是程序逻辑更加清晰可见,在JavaScript中很多对象都有自己的事件,如:button有onc ...

  4. QT中嵌入SDL

    原地址:http://www.qtcn.org/bbs/read.php?tid=23926 前段时间在做一个音视频编码板卡的PC跨平台程序,使用QT框架,其中有块功能是往QT里嵌入SDL,来播放YU ...

  5. Linux命令行之逗趣无极限

    Linux命令行之逗趣无极限 . Linux"sl"命令行 尽管"sl"代表了"蒸汽机机头",但它是用来提醒那些命令行控们别把"l ...

  6. Linux下,查看网络配置(IP,Gateway,DNS)

    查看IP [root@localhost ~]# ifconfigem1       Link encap:Ethernet  HWaddr F0:1F:AF:D6:17:DD            ...

  7. MFC Attach()函数和Detach()函数

    一.Windows对象和MFC对象的区别?MFC对象实际上并没有把整个Windows对象都包装在其中.对于窗口:MFC对象它只是有一个窗口句柄而已,这个窗口句柄如果指向一个实际存在的窗口对象(窗口对象 ...

  8. C11 memory_order

    概念: 摘录自:http://preshing.com/20120913/acquire-and-release-semantics/ Acquire semantics is a property ...

  9. axis2之webservice

    Axis2之webservice超详细教程 Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的 ...

  10. hdu1258Sum It Up (DFS)

    Description Given a specified total t and a list of n integers, find all distinct sums using numbers ...